Thursday, October 4, 2012

Branching Using IF and IF .. ELSE

         IF and IF .. ELSE are branching control structure that is used to run one or more commands before checking with especially given conditions, if the condition is true then a series of statements will be made, if the condition is false then the statement will be executed for the wrong condition.


Syntax :

If(condition){

            Statement

}

Example :

1. Check digit is an odd number or even number

            $x=3;

      if($x%2==0){
            echo $x.“is even number”;
      }else{
echo $x.“is odd number”;
}

2. Check Point

      $x=75;

      If($x>=80){
            echo “point A”;
}else if($x>=60 && $x<=79){
      echo “point B”;
}else if($x>=40 && $x<=59){
      echo “point C”;
}else if($x>=20 && $x<=39){
      echo “point D”;
}else{
      echo “point E”;
}


No comments:

Post a Comment