for command (C and C++)
- Evaluate an expression before the first iteration of the command ("initialization").
- Specify an expression to determine whether the command should be performed again ("controlling part").
- Evaluate an expression after each iteration of the command.
- Perform the command, or block, if the controlling part does not evaluate to false.
The for keyword must be lowercase and cannot be abbreviated.
>>-for--(--+------------+--;--+------------+--;-----------------> '-expression-' '-expression-' >--+------------+--)--command--;------------------------------->< '-expression-'
- expression
- A valid Debug Tool C and C++ expression.
- command
- A valid Debug Tool command.
Debug Tool evaluates the first expression only before the command is performed for the first time. You can use this expression to initialize a variable. If you do not want to evaluate an expression before the first iteration of the command, you can omit this expression.
Debug Tool evaluates the second expression before each execution of the command. If this expression evaluates to false, the command does not run and control moves to the command following the for command. Otherwise, the command is performed. If you omit the second expression, it is as if the expression has been replaced by a nonzero constant and the for command is not terminated by failure of this expression.
Debug Tool evaluates the third expression after each execution of the command. You might use this expression to increase, decrease, or reinitialize a variable. If you do not want to evaluate an expression after each iteration of the command, you can omit this expression.
A break command can cause the execution of a for command to end, even when the second expression does not evaluate to false. If you omit the second expression, you must use a break command to stop the execution of the for command.
Usage notes
- The for command cannot be used while you replay recorded statements by using the PLAYBACK commands.
Examples
- The following for command lists the value of count 20
times. The for command initially sets the value
of count to 1. After each execution of the command, count is
incremented.
for (count = 1; count <= 20; count++) LIST TITLED count;
Alternatively, the preceding example can be written with the following sequence of commands to accomplish the same task.count = 1; while (count <= 20) { printf("count = %d\n", count); count++; }
- The following for command does not contain an
initialization expression.
for (; index > 10; --index) { varlist[index] = var1 + var2; printf("varlist[%d] = %d\n", index, varlist[index]); }