English
Language : 

CC78K0S Datasheet, PDF (123/520 Pages) NEC – C Compiler Ver.1.30 or Later Language
CHAPTER 6 CONTROL STRUCTURES OF C LANGUAGE
(1) while statement
Iteration Statements
while statement
FUNCTION
A while statement executes one or more statements (the body of the while loop) several times as long as the
value of the control expression enclosed in parentheses is true (nonzero). The while statement evaluates the
control expression before executing its loop body.
SYNTAX
while (expression) statements
EXAMPLE
int i, x ;
void main (void){
i=1, x=0 ;
while( i < 11 ){
x += i ;
i++ ;
}
}
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 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).
“while(1) {statement}” is used to endlessly perform a loop statement.
User’s Manual U14872EJ1V0UM
123