:WHILE... :ENDWHILE

The :WHILE script statement defines a loop. Use a :WHILE block when you need parts of a script to execute several times until a condition is no longer met.

While a particular condition applies, the :WHILE statement loops a process in the script. The condition is a logical expression that supplies either a true or false result. When the condition is true, the statements in the loop are processed. The condition is re-evaluated and if the condition is still true, the statements are processed again. This process repeats until the condition is no longer true, in which case the loop ends and the script continues with the line that follows the :ENDWHILE statement.

Syntax

:WHILE condition
[statements]
:ENDWHILE

Parameters

Notes:

Use the following structure to write conditions:

Value Comparison operator Comparison Value [OR Comparison Value...]

The following comparison operators are available for conditions:

Examples

The following condition is true:

:WHILE "0" = "0"

The following condition is false:

:WHILE "0" = "abc"

The length does not matter when you compare strings. The following condition is true because S comes before W in the alphabet:

:WHILE "Smith" < "Wilson"

The following script statement defines a condition that requires a variable to have one of two possible values in order to be true. If the condition is true, the :WHILE block script lines are processed.

:WHILE &ABT# = "EDP" OR "AE"

The following example requests a user to enter a name and a department. The request is repeated until the user enters a name that is not his or her own name.

:SET &REPEAT# = "Y"

 

:WHILE &REPEAT# = "Y"

:SET &DEP# = SYS_USER_DEP()

:SET &NAME# = SYS_USER_NAME()

 

:BEGINREAD 

:   READ &DEP#, "08" ,"Please enter a department", &DEP#, "M" 

:   READ &NAME#, "08", "Please enter a name", &NAME#, "M" 

:ENDREAD

 

:IF SYS_LAST_ERR_NR() <> 0

:   STOP

:ELSE

:   IF SYS_USER_NAME() = &NAME#

:      SET &REPEAT# = "Y"

:      SET_LAST_ERR 10006, "Please enter a name that is not your own name"

:   ELSE

:      SET &REPEAT# = "N"

:   ENDIF

:ENDIF

 

:ENDWHILE

See also: