Summary of IF Statements
If statements can have any of the formats below:
//One statement to execute when True:
if (Boolean expression) statement;
//One statement to execute when True, one when false:
if (Boolean expression)
statement;
else statement;
//Using blocks: one or more statements to execute when true, one or more when false:
if (Boolean expression) {
statement;
statement;
} // end of true block
else {
statement;
statement;
} // end of false block
//If Else Group: more than one condition to test
if(Boolean expression1) {
statement;
statement;
} // end of block for first condition
else if(Boolean expression2) {
statement;
statement;
} // end of block for second condition
// as many else if blocks as needed
else { // block to execute if none of the other conditions is met
statement;
statement;
{
Example of an else if block: Test this by putting values for avg in the URL.
TEST PAGE
if($avg>=90) echo 'A';
else if($avg>=80) echo 'B';
else if($avg>=70) echo 'C';
else if($avg>=60) echo 'D';
else echo 'F';
INDEX,
Boolean Values,
if/else,
Summary,
Compound Conditions: AND && and OR ||,
SWitchNext lesson:
Important InformationMAIN INDEX
EXAMPLES INDEX