Khushi Sharma Tuesday May 15 , 2012
The ‘If-Else’ Statement
-Boolean expression is one which evaluates to a Boolean value
X > Y is X greater than Y?
X < Y is X less than Y?
X >= Y is X greater than or equal to Y?
X <= Y is X less than or equal to Y?
X = Y is X equal to Y?
X! = Y is X not equal to Y?
The IF Statement
-the IF statement decides whether a section of codes executes or not
-the IF statement used a Boolean to decide whether the next statement of blocks of statements
-there are only two possible values for Boolean expressions:
-you can construct simple Boolean expressions from the relational operators which are below
Rational Operators Meaning
> Less than
< Greater than
<= less than or equal
>= greater than or equal
!= not equals
The IF-ELSE Statement – Details:
-syntax of the java if-else statement is as below:
-if and else are Java reserved words, which give the if-else statement its structure and tell the complier
that this is an if-else statement
-the is a Boolean expression
-the and are Java statements Khushi Sharma Tuesday May 15 , 2012
IF – ELSE Matching:
-curly braces use is not required if there is only one statement to be conditionally executed
-sometimes curly braces can help make the program more readable
-indentation makes it much easier to match up else statements with their corresponding if statement
Nested IF – ELSE Stat