Branching Alternatives if else Condition

 if else Condition 

    The if keyword is used to perform the basic condition text that evaluates a given expression for a boolean value of TRUE or FALSE . Statement with in braces following the evaluation will only be exacuted when the expression is found to be true 

Syntax
    if (test expression)
        {
            statement to execute when true
         }

if statement by appending an else statement by appending an else statement specifying within braces to be executed when the expression evaluated by the if statement are found to be FALSE 

Syntax
       if(test-expression)
        {
             statement-to-executed-when-true
        }
  else
        {
           statement-to-executed-when-false
         }


Alternative expression may also be evaluated in a conditional test by adding an ifelse statement specifying statement within braces to be executed when the alternatives expression is found to be TRUE . An else statement can be appended here to specify statement within braces to be executed when the expression evaulated by the if and else if statement are found to be FALSE 

Syntax
    if(test-expression)
     {
         statement-to-execute-when-true
      }
else if(test-expression)
     {
         statement-to-executed-when-alternative-is-true 
      }
else
     {
         statement-to-execute-when-all-expression-are-false
      }



PHP Program

<?php
    if(4>8)
        {
            echo ' 4 is greater than 8';
        }
    else
       {
           echo '4 is less than 8';
       }
     
        
           // Second condition
       if(4>8)
        {
            echo 'this test is true';
        }
  else if (8>4)
        {
            echo 'Alternative test is true';
        }
    else 
       {
           echo 'Both test are false';
       }
?>




output

  

Comments

Post a Comment

Popular posts from this blog

Switching Branches