The for loop
The for loop is used to repeat a set of rules
a given number of times.
The for loop takes the following format.
for( variable_assignment ; conditional_test ; change_to_variable )
{
List of stitcher rules to execute
}The process flow of the for loop
is as follows:
- On the first loop, the
variable_assignmentassigns a value to a previously declared variable. - The
conditional_testis evaluated. - If the test evaluates true:
- The stitcher rules within the curly braces are executed.
- The
change_to_variableis performed. - The loop returns to step 2.
- When the
conditional_testevaluates false, the loop terminates.
Example
The following example shows a for loop.
This loop repeats until variable1 is no longer less than variable2 (variable1 is
increased by 1 on each complete loop).
int variable1 = 0; // Declares variable1 as an integer.
for( variable1 = 0 ; variable1 < variable2 ; variable1 = variable1 + 1 )
{
List of stitcher rules to execute
}