xhtml
 

Nesting

You can put one test inside another. In fact, you can put an if inside either the then clause or the else clause of another if, or both:

if (test1)
{
   ...
   if (test2)
   {
      ...
   }
   ...
}
else
{
   ...
   if (test3)
   {
      ...
   }
   ...
}

Each if statement may or may not have an else clause. You could even put more if statements inside the inner if statements, and so on, but then the program gets very difficult to follow, and it might be better to find a way to design the logic in simpler steps.


Back