Most programming languages support the for
-loop control structure.
It is generally implemented in this way:
for(init; condition; increment){
content_code();
}
The above pseudocode is identical with the pseudocode below:
init;
start_loop:
if(condition){
content_code();
increment;
goto start_loop;
}
This shows that:
init
is run before the loop, used to initialize things for running that loop
init
, and the scope of the declared variables will be limited to that loop.condition
is a condition to determine when the loop can be run. If this evaluates to false
, the loop will stop executing.increment
is usually a statement used to manipulate parameters used in condition
, so when increment
is run a certain number of times, condition
becomes false
and the loop breaks.content_code()
is the core code to be run within the loop.