Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nested conditional statements. A conditional statement (i.e., an if-statement or an if-else- statement) is also a statement We can use an if-statement.

Similar presentations


Presentation on theme: "Nested conditional statements. A conditional statement (i.e., an if-statement or an if-else- statement) is also a statement We can use an if-statement."— Presentation transcript:

1 Nested conditional statements

2 A conditional statement (i.e., an if-statement or an if-else- statement) is also a statement We can use an if-statement or an if-else-statement in the then- part (and in the else-part) of a conditional statement !!! Nested conditional statement = a conditional statement where the then-part and/or the else-part contains another conditional statement

3 Programming example: determine the price for a hair cut (1)

4 Programming example: determine the price for a hair cut (2)

5 Programming example: determine the price for a hair cut (3)

6 Programming example: assign a letter grade to a number grade (1)

7 Programming example: assign a letter grade to a number grade (2)

8 Programming example: assign a letter grade to a number grade (3)

9 Programming example: assign a letter grade to a number grade (4)

10 Programming example: assign a letter grade to a number grade (5)

11 Programming example: assign a letter grade to a number grade (6)

12 A three-way selection construct (1) A two-way selection is a choice between 2 mutually exclusive cases:

13 A three-way selection construct (2) A three-way selection is a choice between 3 mutually exclusive cases:

14 A three-way selection construct (3) A common way to ensure that the 3 choices are mutually exclusive is as follows:

15 A three-way selection construct (4)

16 A three-way selection construct (5)

17 The N-way selection construct (1) A N-way selection construct looks like the following:

18 The N-way selection construct (2)

19 The switch statement: an N- way selection statement (1) an intrinsically N-way selection statement: the switch statement

20 The switch statement: an N- way selection statement (2) INT-EXPRESSION must be an integer valued expression The result of the INT-EXPRESSION is compared to the integer values given in the case clauses The statements following the case clause up to the break statement are executed If the result of the INT-EXPRESSION is not equal to any INT-VALUE in the case clauses, then the statements in the default case are executed

21 The switch statement: an N- way selection statement (3)

22 The switch statement: an N- way selection statement (4) The following types are automatically converted into an integer typed value in expressions:

23 The switch statement: an N- way selection statement (5)


Download ppt "Nested conditional statements. A conditional statement (i.e., an if-statement or an if-else- statement) is also a statement We can use an if-statement."

Similar presentations


Ads by Google