Programming Guide |
Executes one or more JPL statements the specified number of times
forcounter
=initValue
whilelogicalExpr
[ stepstepValue
]
[statementBlock
]
counter
- A variable whose value may be tested as a condition for continuing or ending for execution
initValue
- The initial value of counter
logicalExpr
- Specifies the condition for continuing for execution. Execution remains inside the for loop until
logicalExpr
evaluates to false. You can specify multiple conditions with the logical operatorsAND
(&&) andOR
(||).step
stepValue
- Optionally specifies the value by which counter is incremented or decremented, where
stepValue
is a positive or negative integer constant or variable. The default step value is 1. IfstepValue
is a variable, JPL evaluates it only once, before the first evaluation oflogicalExpr
. Subsequent changes in the value of thestepValue
variable during loop execution have no effect on step processing.statementBlock
- One or more JPL statements to execute as long as
logicalExpr
evaluates to true. IfstatementBlock
has multiple statements, enclose them with open and close blocking characters {0} on the lines before and after. If there is no statement to execute, enter a null statement {}.
The
for
command starts a loop whose iterations increment a counter variable. Each for statement contains up to three clauses–initialization of the counter variable, a logical expression whose evaluation determines whether to reenter the loop, and optionally, the number by which to increment the counter variable. Panther executes a for statement as follows:When the value of
logicalExpr
is false, JPL stops loop execution. In the simplest case, it compares counter to a value that specifies the number of times that JPL executes the loop. You can use other values to decide when loop execution ends. For example, you can use counter to evaluate array occurrences and use the value of an occurrence, like a null string, to the end the loop.When you construct a logical expression, take into account that JPL, unlike C, always fully evaluates a boolean expression. For example, the following for statement traverses a screen's fields by field number (ct) until the last field or the first modified field is reached:
vars ct
vars n_flds = @screen("@current")->numflds
for ct = 1 while ct <= n_flds && @field_num(ct)->mdt == PV_NOIf all fields are unmodified, ct increments to one greater than
n_flds
on the last pass through the for loop, so the first condition evaluates to false; however, JPL also evaluates the second condition@field_num(ct)
, which is invalid. Consequently, JPL issues an error message and stops execution of the remaining code.
// Change each element of an array to its absolute value.
vars i
for i = 1 while i <= 10 step 1
{
if amounts[i] == ""
amounts[i] = "0"
else if amounts[i] < 0
amounts[i] = -amounts[i]
}
next, break, while