DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C language compiler

Selection statements

if

   if (expression)
        statement

else

   if (expression1)
      statement1
   else if (expression2)
      statement2
   else
      statement3

switch

   switch (expression)
        statement
In practice, statement is usually a compound statement with multiple cases, and possibly a default; the description above shows the minimum usage. In the following example, flag gets set to 1 if i is 1 or 3, and to 0 otherwise:
   switch (i) {
   case 1:
   case 3:
   	flag = 1;
   	break;
   default:
   	flag = 0;
   }

Next topic: Iteration statements
Previous topic: Compound statement

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003