English
Language : 

CC78K4 Datasheet, PDF (119/523 Pages) NEC – CC78K4 Ver.2.30 or Later, C Compiler Language
CHAPTER 6 CONTROL STRUCTURES OF C LANGUAGE
(3) for statement
Iteration Statements
for statement
FUNCTION
A for statement executes the body of the for loop a specified number of times as long as the value of the control
expression is nonzero (True). Of the three expressions inside the parentheses separated by semicolons, the first
expression is an initializing statement to initialize a variable to be used as a counter and is executed only once in
the beginning of the loop, the second is the control expression for testing the counter value, and the third is a
step statement executed at the end of every loop and reevaluates the variable after the execution.
SYNTAX
for ( 1st-expression ; 2nd-expression ; 3rd-expression) statements
EXAMPLE
int i, x=0 ;
for( i=1 ; i<11 ; ++i )
x += i ;
EXPLANATION
The above example finds the sum total of integers from 1 to 10 for x. “x+=i” is the body of this for 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).
NOTE
When the processing after for statement is not enclosed with “{ }”, only the processing of a line after the for
statements is regarded as the body of the loop of the for statement. The first and the third expression of a for
statement can be omitted. When the second expression is omitted, it is replaced with a constant other than 0.
The description of “for (; ;) statement” is used to endlessly perform the body of the loop.
User’s Manual U15556EJ1V0UM
119