O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nesting

A nested if statement forms part of a code block that is executed after the evaluation of another if, else, or else if clause. In other words, you can use an if statement inside another. Like a nest of tables, or Russian dolls contained one inside the other, nesting is a way to narrow down the result until you get to a point where you can execute some code.

It is always easier to show, rather than just describe, C programming, so here is a possible nested if statement:

if ( nValue < 10 )
{
      // Execute code

      if ( nValue < 5 )
      {
            // This will also execute
            // if the condition is satisfied.
      }
      // Code here would also be executed
}

There are two very important points to note. First, the nested if statement is treated as if it is in isolation. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required