If statements in C Programming

The different form of if statements with their syntax and semantic diagram are:-

if statements:-

                          The if statement evalutes the test expression inside the parenthesis. If the test expression is evaluated to true(non zero), statements inside the body of it is executed. If the test ecpression is evaluated to false(0), statements inside the body of if is skipped from execution.
The Syntax and Sementics diagram is :
if (test expression)
{(statements)
}


If statements
                                                                                                             


if else statement:

                               The if else statement executes some code if the test expression is true (nonzero) and some other code if the expression is false(0). If tested expression is true, codes inside the body of if statement is executed and, codes inside the body of else is skipped. And when it is false codes inside the body of else is executed and codes inside the body of if statement is skipped.
The syntax and semantic diagram are:-
if (test expression)
{//codes inside the body of if
}
else
{// codes inside the body of else}
If statements


Nested if....else statement (if ...... else if ....... else statement)


                      The if ..... else statement executes two different codes depending upon whether the test expression is true or false.  Sometimes, a choic has to be made from more than 2 possibilities. The nested if ...... else statements allows ypu to check for multiple test expression and execute different codes for more than two condition.
The syntax is
  if (condition1)     
statement – 1; 
else if (condition2)     
statement2;
else if (condition3)     
statement3; 
else if (condition n)     
statement n;
else     
default statement;
statement-x;


Nested if statements:-

  if statement may be nested as deeply as you need to nest it. One block of code will only be executed if two conditions are true. Condition 1 is tested first and then condition 2 is tested. The second if condition is nested in the first.  The second if condition is tested only when the first condition is true else the program flow will skip to the corresponding else statement.
 The if statement may itself contain another if statement is known as nested if statement.   
Syntax:
          if (condition1)                 
          if (condition2)                               
              statement-1;           
                     else                               
                          statement-2;           
                     else                                 
                          statement-3; 
Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours