Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming 12 Mr. Jean April 2 nd, 2014.

Similar presentations


Presentation on theme: "Computer Programming 12 Mr. Jean April 2 nd, 2014."— Presentation transcript:

1 Computer Programming 12 Mr. Jean April 2 nd, 2014

2 The plan: Video clip of the day If else statements Nested If statement

3 The if-else Statement There is an expansion of the if statement called the if-else statement. if(BooleanExpression) statement or block 1 else statement or block 2 Just like the if statement, BooleanExpression is evaluated. If it resolves to true, then statement or block 1 is executed If it resolves to false, then statement or block 2 is executed

4 if-else Flowchart Boolean Expression Statement 1 Statement 2 Statement 3 True False Statement 4 Statement 5 Statement 6

5 Nested if Statements Nesting is enclosing one structure inside of another. A block in Java can contain any valid Java code, this includes other if statements: if(BooleanExpression1) { if(BooleanExpression2) { statement1; statement2; } statement3; statement4; } If BooleanExpression1 is true and BooleanExpression2 is true, what is executed? statement1, statement2, statement3, statement4 If BooleanExpression1 is true and BooleanExpression2 is false, what is executed? statement3, statement4 If BooleanExpression1 is false, what is executed? Nothing

6 Logical AND and Nesting If we have the && operator, do we need nesting? if(BooleanExpression1) { if(BooleanExpression2) { Both conditions met } else { Both conditions NOT met } } else { Both conditions NOT met } if(BooleanExpression1 && BooleanExpression2) { Both conditions met } else { Both conditions NOT met }

7 Logical AND and Nesting Answer: Yes, to act if one of the conditions is not met: if(BooleanExpression1) { if(BooleanExpression2) { Both conditions met } else { Condition 2 not met } } else { Condition 1 not met } if(BooleanExpression1 && BooleanExpression2) { Both conditions met } else { Both conditions NOT met }


Download ppt "Computer Programming 12 Mr. Jean April 2 nd, 2014."

Similar presentations


Ads by Google