If...Else...Elseif Statements: if statement executes some code if one condition is true.
Switch Statement: Switch Statement tests a variable against a series of values.
For Loop: For loop executes a block of code a specified number of times.
While Loop: Whil...
We are covering following topics:
If...Else...Elseif Statements: if statement executes some code if one condition is true.
Switch Statement: Switch Statement tests a variable against a series of values.
For Loop: For loop executes a block of code a specified number of times.
While Loop: While loop executes a block of code as long as the specified condition is true.
Do…While Loop: Do...While loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.
We are covering following topics If...Else... Elseif Statements Switch Statement For Loop While Loop Do…While Loop
IF …. ELSE …. ELSEIF if statement executes some code if one condition is true. if...else statement executes some code if a condition is true and another code if that condition is false. if... elseif ....else statement executes different codes for more than two conditions.
Example of if... Elseif ...Else <? php $date = date("D"); if ($date == "Friday"){ echo "Have a nice weekend!"; } elseif ($date == "Sunday"){ echo "Have a nice Sunday!"; } else { echo "Have a nice day!"; } ?>
Output (If…Else… Elseif )
Switch Statement Switch Statement tests a variable against a series of values. We can assume Switch Statement is an alternative to the if… elseif …else statement.
Example of Switch Statement <? php $date = date("D"); Switch ($date) { case "Friday ": echo " Have a nice weekend " ; break; case "Sunday": echo " Have a nice Sunday! " ; break; default: echo " Have a Nice Day! " ; break; } ?>
Output (Switch Statement)
For Loop For loop executes a block of code a specified number of times. Basic Syntax of For Loop: for ( init counter ; test counter ; increment counter ) { code to be executed; }
Example of For Loop <? php for ($x = 0; $x <= 10; $x++) { echo "The number is: " . $x . "< br >"; } ?>
Output (For Loop)
While Loop While loop executes a block of code as long as the specified condition is true. Basic Syntax of While Loop: while ( condition is true ) { // code to be executed ; }
Example of While Loop <? php $ x = 1; while($x <= 5) { echo "The number is: $x < br >"; $x++; } ?>
Output (While Loop)
Do…While Loop Do...While loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true. Basic syntax of Do…While Loop: do { // code to be executed; } while ( condition is true );
Example of Do…While Loop <? php $x = 6; do { echo "The number is: $x < br >"; $x++; } while ($x <= 5); ?>