Social Icons

10 July 2012

0 Else-if statement in C

else if condition is nothing but this this a way to arrange the else with the if that follows it.Every else is associated with its previous if. The last else goes to work only if all the conditions fail.Also, if the first condition is satisfied, other conditions are not checked.Last else is optional.

Syntax-

------------
------------
if(condition)
  {
    ---------
    ---------
  }
else if(condition)
  {
   ---------
   ---------
  }
else if(condition)
 { 
   ---------
   ---------
  }
 .          .
 .          .
 .          .
else
  {
   --------
   --------
  }
----------
----------

Example-
/*Demonstration of else if */
#include<stdio.h>
 int main()
  {
   int i=5;
   if ( i <5 )
     {
       printf ( "Less than 5." ) ;
     }
  else if(j==5)
     {
       printf("Equal to 5.");
     }
   else
     {
       printf("Greater than 5.")  
     }
   return 0;
}

0 comments:

Post a Comment

Hey this is a test comment

Related Posts Plugin for WordPress, Blogger...