KEMBAR78
Statements and Conditions in PHP | PPTX
WELCOME TO
OUR PRESENTATION
MEMBERS INTRO
 MD. IMRAN HOSSAIN {{ 183-25-691 }}
 MARUF ABDULLAH {{ 183-25-706 }}
 FAHIM FOYSAL KHAN {{ 183-25-692 }}
 SUMON HAZRA {{ 181-25-644 }}
 PRITOMA DEBNATH {{ 181-25-653 }}
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);
?>
OUTPUT (DO …. WHILE LOOP)
THANK YOU

Statements and Conditions in PHP

  • 1.
  • 2.
    MEMBERS INTRO  MD.IMRAN HOSSAIN {{ 183-25-691 }}  MARUF ABDULLAH {{ 183-25-706 }}  FAHIM FOYSAL KHAN {{ 183-25-692 }}  SUMON HAZRA {{ 181-25-644 }}  PRITOMA DEBNATH {{ 181-25-653 }}
  • 3.
    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!"; } ?>
  • 6.
  • 7.
    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; } ?>
  • 9.
  • 10.
    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>"; } ?>
  • 12.
  • 13.
    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++; } ?>
  • 15.
  • 16.
    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); ?>
  • 18.
    OUTPUT (DO ….WHILE LOOP)
  • 19.