Download presentation
Presentation is loading. Please wait.
1
July 13 th
2
If/ Else if / Else Variable Scope Nested if/else's Switch statements Conditional Operator
3
int result = 0; if (x > 0) { result += x; } else { result -= x; }
4
int result = 0; if ( ) { } else if( ) { } else if … else { } The boolean expressions are evaluated in sequence from top to bottom. The first boolean expression that evaluates to true has its associated expression list executed. Once a single boolean expression is matched, no more are considered.
5
The scope of a variable is defined as the section of code in which a variable is defined. Outside of a variable’s score, the variable does not exist. The start of a ‘local’ variable’s scope is where it is declared: int x; //x’s scope begins
6
if( boolean expression) { … if(boolean expression) { … } else if(boolean expression) { … } else {... }
7
The scope a variable defined in the expression list of an if statement is the expression list. int y = 0; if(x > 0) { int x = a * b; y = x - a/b; } Scope of y Scope of x
8
boolean expression ? expression 1 :expression 2 If the initial boolean expression is true, then expression 1 is executed, if the boolean expression is false then expression 2 is executed. int s = (x < 0) ? -1 : x * x; int max = (a > b) ? a : b; int sign = ( number < 0) ? -1 : ((number == 0) ? 0 : 1);
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.