English
Language : 

CC78K0S Datasheet, PDF (124/520 Pages) NEC – C Compiler Ver.1.30 or Later Language
CHAPTER 6 CONTROL STRUCTURES OF C LANGUAGE
(2) do statement
Iteration Statements
do statement
FUNCTION
A do statement executes the body of the loop and then tests the control expression enclosed in parentheses to
see if its value is true (nonzero). The do statement evaluates the control expression after the loop body has
been executed.
SYNTAX
do statements while (expression);
EXAMPLE
int i, x;
void main(void){
i=1,x=0;
do{
x+=i;
i++;
}while(i<11);
}
EXPLANATION
The above example finds the sum total of integers from 1 to 10 for x. The two statements enclosed in braces are
the body of this do ... while loop. The control expression “i<11” returns 0 if the value of i becomes 11. For this
reason, the loop body is executed repeatedly as long as the value of i is less than 11 (between 1 and 10). The
body of the loop is always performed once or more since the control expression of a do statement is evaluated
after execution.
124
User’s Manual U14872EJ1V0UM