You are here

Nested Control Structures

10 February, 2015 - 14:06

We are going to first introduce the concept of nested control structures. Nesting is a concept that places one item inside of another. Consider:

if expression   true action 
else   false action 

This is the basic form of the if then else control structure. Now consider:

if age is less than l8   you can't vote   if age is less than l6     you can't drive else you can drive else   you can vote   if age is less than 2l     you can't drink   else     you can drink 

As you can see we simply included as part of the "true action" a statement and another if then else control structure. We did the same (nested another if then else) for the "false action". In our example we nested if then else control structures. Nesting could have an if then else within a while loop. Thus, the concept of nesting allows the mixing of the different categories of control structures.

Many complex logic problems require using nested control structures. By nesting control structures (or placing one inside another) we can accomplish almost any complex logic problem.