How do i input an if else statement inside an already existing if else statement?

Recommended Answers

All 5 Replies

use brackets like this:

if (i < 0)
{
    if (i < 10)
    {
        ...
    }
    ...
}

Are you asking about something like this?

if(something)
{
    if(somethingelse)
    {
        //...
    }
    else
    {
        //...
    )
}
else
{
    if(somethingelse)
    {
        //...
    }
    else
    {
        //...
    }
}

oops i forgot to add else:

if (test)
{
    if (another_test)
    {
        ...
    }
    else
    {
        ...
    }
    ...
}
else
{
    ...
}

Thank you guys, real big help on my code.

  if(true)
      do_this;
   else if(true)
      do_this;
   else if(true)
      do_this;
   else if(true)
      do_this;
   else if(true)
      do_this;

This is called a decesion tree, and only one if statement will execute out of the whole bunch. When one of the if statements does execute, then control drops out to the bottom bypassing all the other remaining if statements.

Actually, they are not called else-if statements but rather they are the regular if-else statements just written that way for clarity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.