Instructions Circuit Diagram
- 81 -
for(…){
}
The program module enclosed in ‘for’-brackets ‘{‘ respectively ‘}’ will be
called a ‘loop’.
int i;
ThisstatementdenesaVariablewithafreechosenname‘i’.
for(i=0 ;i<5 ;i++){
Initiate variable ‘i’ with value 0 and repeat all program coding between
the opening bracket ‘{‘ and the corresponding closing bracket ‘}’, as
long as variable ‘i’ is less than 5. Any time the program meets the ‘for’-
line in the source coding the value in ‘i’ is incremented by 1. The very
rsttimetheprogrammeetsthe‘for’-lineinthesourcecodingthevalue
in ‘i’ is 0.
At the 6e passage ‘i’ reaches the value 5 and no longer meets the con-
dition i<5, which will force the program to continue at the next coding
line, following the closing bracket ‘}’ at the ‘for’-loop. In our example
this line reads: return 0;
The program executed the ‘for’-loop 5 times, which is exactly what we
wanted to be done.