













































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














































































that
a sequential flow:
Syntax:
if (condition) statement executed if condition is true; else statement executed if condition is false;
if-then-else performs instructions based on
the result of a comparison Place statements on separate lines for readability
Syntax:
if ( Condition )
StatementA
else
StatementB
NOTE: StatementA and StatementB each can be a
single statement, a null statement, or a block.
if ( Condition ) {
} else {
}
int carDoors, driverAge ; float premium, monthlyPayment ;
... if ( (carDoors == 4 ) && (driverAge > 24) ) { premium = 650.00 ; System.out.println(“ LOW RISK “ ); } else { premium = 1200.00 ; System.out.println(“ HIGH RISK ”) ; }
monthlyPayment = premium / 12.0 + 5.00 ;
if ( (carDoors == 4 ) && (driverAge > 24) ) premium = 650.00 ; System.out.println(“ LOW RISK “) ; else premium = 1200.00 ; System.out.println(“ HIGH RISK ”) ;
monthlyPayment = premium / 12.0 + 5.00 ;
COMPILE ERROR OCCURS. The “if clause” is the single statement following the if.
! p NOT p! p is false if p is true ! p is true if p is false
p && q p AND q p && q is true if both p and q are true. It is false otherwise.
p || q p OR q p || q is true if either p or q or both are true. It is false otherwise.
Example: