Nested Statements

The general form templates use the line:

  <statement>

to indicate that any valid statement can be inserted in that location in the code. When a statement includes another statement of the same kind, we call that a nested statement. We can expand the template for the if...else statement to include another if...else statement:

if (<boolean condition>)
  if (<boolean condition>)
     <statement>
  else
    <statement>
else
  <statement>

This is called a nested if statement, and we have seen it already. When we nest loop statements, we call them nested loops, and it is common to see them in many programs.

Previous page
Next page

Back to Lesson 10 Index
Back to Outline