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:

  1. On the first loop, the variable_assignment assigns a value to a previously declared variable.
  2. The conditional_test is evaluated.
  3. If the test evaluates true:
    • The stitcher rules within the curly braces are executed.
    • The change_to_variable is performed.
    • The loop returns to step 2.
  4. When the conditional_test evaluates 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
        }