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

Statements

Expression statement

   expression;
The expression is executed for its side effects, if any (such as assignment or function call).

Compound statement

   {
   	declaration-list[opt]
   	statement-list[opt]
   }

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;
   }

Iteration statements

while

   while (expression)
        statement
This sequence is followed repetitively: expression must have scalar type.

do-while

   do
        statement
   while (expression);
This sequence is followed repetitively:
(do-while tests loop at the bottom; while tests loop at the top.)

for

   for (clause1; expression2; expression3)
        statement

Jump statements

goto

   goto identifier;

break

Terminates nearest enclosing switch, while, do, or for statement. Passes control to the statement following the terminated statement. Example:

   for (i=0; i<n; i++) {
      if ((a[i] = b[i]) == 0)
         break;	/* exit for */
   }

continue

Goes to top of smallest enclosing while, do, or for statement, causing it to reevaluate the controlling expression. A for loop's expression3 is evaluated before the controlling expression. Can be thought of as the opposite of the break statement. Example:

   for (i=0; i<n; i++) {
      if (a[i] != 0)
         continue;
      a[i] = b[i];
      k++;
   }

return

   return;
   return expression;

Previous topic: Initialization

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004