Programming Guide


Repeatedly executes a block while a condition is true


while logicalExpr


Specifies the condition that JPL uses to determine whether to reiterate execution of the while block.

One or more statements that JPL executes if logicalExpr evaluates to true. If statementBlock has more than one statement, enclose the block with open and close blocking characters {0} on the lines before and after.


The while statement repeatedly executes a block of one or more statements as long as the value of logicalExpr is true. JPL evaluates logicalExpr before each iteration of the loop.


// do do_proc as often as user wants
vars ans
ans = sm_message_box \
("Start processing?","",SM_MB_YESNO, "")
while ans
call do_proc
ans = sm_message_box \
("Repeat processing?","",SM_MB_YESNO, "")

When you construct a logical expression, take into account that JPL, unlike C, always fully evaluates a boolean expression. For example, the following while loop 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

while ct <= n_flds && @field_num(ct)->mdt == PV_NO
ct = ct + 1

If all fields are unmodified, ct increments to one greater than n_flds on the last pass through the while 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.

See Also

break, for, next