Do While (DOWHILE)

Where allowed to run:
  • Batch program (*BPGM)
  • Interactive program (*IPGM)
Threadsafe: Yes
Parameters
Examples
Error messages

The Do While (DOWHILE) command evaluates a logical expression and conditionally processes 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:

Top

Parameters

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

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 concepts and reference topic in the iSeries Information Center at http://www.ibm.com/eserver/iseries/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.

This is a required parameter.

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

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.

Top

Error messages

None

Top