DOWHILE command in a CL program or procedure

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

The DOWHILE command is used to state a condition that, if true, specifies a command or group of commands in the program or procedure to run. The group of commands is defined as those commands between the 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 can 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 example is about conditional processing with a 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 can be used to exit the DOWHILE group and resume processing following the ENDDO. The ITERATE command can be used to skip the remaining commands in the group and evaluate the stated condition immediately.