{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# alg3 - Basics of Algorithms Chapter 3 Nested Conditional...

This preview shows pages 1–3. Sign up to view the full content.

Nested Conditional Statements The if-else statement can be nested to allow the programmer the ability to program a complex decision structure. The general form of a nested if-else statement is shown below: if (<boolean expression1>) <statements 1> else if (<boolean expression2>) <statements 2> else if (<boolean expression3>) <statements 3> . . . else <statements n> statement A statement B . . . This statement is executed as: 1. Check if <boolean expression1> is true 2. If so, then execute block of statements <statements 1> 3. If not, check if <boolean expression2> is true 4. If so, then execute block of statements <statements 2> 5. If not, check if <boolean expression3> is true 6. Continue in this fashion until one of the boolean expressions is true 7. Skip all remaining blocks of statements and continue execution with statement A, …. Note: The else clause is always optional. There may be cases in which you do not want to execute any statements based upon a particular decision. Algorithms - 26 Basics of Algorithms – Chapter 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document