4.2.10. while

Evaluates an expression and executes one or more statements until the expression evaluates to False.

Syntax:

while (expression)               /* while this expression is True */
{
    statement;                   /* execute this statement */
    [statement;]...              /* and these additional statements */
}

where:

expression

The expression to be evaluated at the start of each loop.

Description

The while statement evaluates an expression and executes the following statement or statements until the expression evaluates to False.

The while statement must be followed by an expression in parentheses. As long as the expression evaluates to True, all following statements are repeatedly executed. When the expression evaluates to False, all statements are bypassed and execution continues at the next statement outside the while loop. If you have more than one statement in the loop these must be enclosed in curly braces ({}).

Return Value

None

Rules

None

Example

This example shows how to use while in a macro:

define /R void whileloop()
{
  int x;
  x = 1;
  while (1) {
    $printf "Iteration: %d\n", x$;
     if (x > 10) {
      $printf "Done!\n"$;
      break;
    } else if (x==5) {
      $printf "Halfway there...\n"$;
    }
    x++;
  }
}
.

See also

Copyright © 2002-2009 ARM Limited. All rights reserved.ARM DUI 0175K
Non-Confidential