The presentation introduces multiple programming concepts, including if...else...elseif statements, switch statements, and various types of loops (for, while, and do...while). Each concept is accompanied by basic syntax and example code in PHP, demonstrating how to implement these statements. The presentation concludes with a brief thank you note.
WE ARE COVERINGFOLLOWING TOPICS
If...Else...Elseif Statements
Switch Statement
For Loop
While Loop
Do…While Loop
4.
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.
5.
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!";
}
?>
SWITCH STATEMENT
SwitchStatement tests a variable against a
series of values.
We can assume Switch Statement is an
alternative to the if…elseif…else statement.
8.
EXAMPLE OF SWITCHSTATEMENT
<?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;
}
?>
FOR LOOP
Forloop 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;
}
11.
EXAMPLE OF FORLOOP
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: " . $x . "<br>";
}
?>
WHILE LOOP
Whileloop 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;
}
14.
EXAMPLE OF WHILELOOP
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
DO…WHILE LOOP
Do...Whileloop 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);
17.
EXAMPLE OF DO…WHILELOOP
<?php
$x = 6;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>