DOWHILE command

The DOWHILE command lets you process a group of commands zero or more times while the value of a logical expression is true.

The Do While (DOWHILE) command is used to state a condition that, if true, specifies a command or group of commands in the procedure to run. The group of commands is defined as those commands between the Do While (DOWHILE) and the matching End DO (ENDDO) command.

After the group of commands is processed, the stated condition is evaluated. If the condition is false, the DOWHILE group will be exited and processing will resume with the next command following the associated ENDDO. If the condition is true, the group will continue processing with the first command in the group. When the ENDDO command is reached, control returns to the DOWHILE command to again evaluate the condition.

The logical expression on the COND parameter may be a single logical variable or constant, or it must describe a relationship between two or more operands; the expression is then evaluated as true or false.

The following is an example of conditional processing with a Do While (DOWHILE) command.

DOWHILE (&LGL)
  .
  .
  .
  IF (&INT *EQ 2) (CHGVAR &LGL '0')
ENDDO

When the DOWHILE group is processed, the stated condition will be evaluated. If the condition is true, the group of commands in the DOWHILE group is processed. If the condition is false, processing continues with the command following the associated ENDDO command.

If the value of &LGL is true, the commands in the DOWHILE group will be run until &INT is equal to 2 causing the &LGL variable value to be set to false.

The Leave (LEAVE) command may be used to exit the DOWHILE group and resume processing following the ENDDO. The ITERATE command may be used to skip the remaining commands in the group and evaluate the stated condition immediately.

Related reference
*AND, *OR, and *NOT operators
Related information
CL command finder
Do While (DOWHILE) command