Do While (DOWHILE)

The Do While (DOWHILE) command evaluates a logical expression and conditionally processes CL program or ILE CL procedure commands according to the evaluation of the expression. If the logical expression is true (a logical 1), the commands in this Do While group are processed as long as the expression continues to evaluate to TRUE. If the logical expression evaluates to false (a logical 0), control passes to the next command following the associated ENDDO command.

Restrictions:

Parameters

Keyword Description Choices Notes
COND Condition Logical value Required, Positional 1

Condition (COND)

Specifies the logical expression that is evaluated to determine a condition in the program and whether the loop is processed again. Refer to "Logical Expressions" in the CL topic collection in the Programming category in the IBM i Information Center at http://www.ibm.com/systems/i/infocenter/ for a description of logical expressions. Note that variables, constants, and the %SUBSTRING, %SWITCH, and %BINARY built-in functions can be used within the expression.

To test if a pointer has a null value, the CL pointer variable can be compared to the special value *NULL if the CL source is being compiled with the Create CL Module (CRTCLMOD) or Create Bound CL Program (CRTBNDCL) command. If the CL source is being compiled with the Create CL Program (CRTCLPGM) command, compare the CL pointer variable to another CL pointer variable that was declared with ADDRESS(*NULL) and has not been changed.

This is a required parameter.

logical-value
Specify the name of a CL logical variable or a logical expression.

Examples

Example 1: DOWHILE Command Group That is Never Processed

DCL   VAR(&LGL)  TYPE(*LGL)  VALUE('0')      /* False */
 :
DOWHILE   COND(&LGL)
 :   (group of CL commands)
ENDDO
 :

The group of commands between the DOWHILE and ENDDO will not be processed because the initial value of &LGL is false. Control will pass to the command following the ENDDO.

Example 2: DOWHILE Forever Command Group

DCL   VAR(&LGL)  TYPE(*LGL)  VALUE('1') /* True */
 :
DOWHILE &LGL
 :   (group of CL commands)
ENDDO
 :

The group of commands between the DOWHILE and ENDDO will be processed until the value of &LGL is set to false (a logical 0). This loop will continue until a LEAVE command or a GOTO command specifying a label outside the DOWHILE group is run.

Error messages

None