:WHILE... :ENDWHILE

ScriptEigener Objekttyp in der Automation Engine Statement: Defines a loop in which scripting parts can be executed several times.

Syntax

:WHILECondition
[Statements]

:ENDWHILE

Syntax

Description/Format

Condition

An expression that consists of script literals, script variables, script functions or numerical expressions and supplies the results "True" or "False".

Statements

One or several statements that are processed until the Condition is "True".
Format: script statement.

Comments

The :WHILE statement is a control structure that can be used to process parts of a script several times depending on the results of a condition. A condition is a logical expression.

The statements are processed when the condition is met (true). The condition is then re-evaluated and the statements are re-processed if the condition is met. This process is repeated until the condition is no longer met (wrong). In this case, the script continues with the line that follows the :ENDWHILE statement.

Note that a terminating condition is required because otherwise, an endless loop occurs.

WHILE blocks can also be nested. Block depths are not limited.

Conditions show the following structure:

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

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

A condition can comprise of up to 13 ORs.

A condition consists of one of the following comparison operators:

Operator

Abbreviation

Rule

=

EQ

The expression is "True" if at least one of the Comparison Values equals Value.

<>

NE

The expression is "True" if none of the Comparison Values equals Value.

<

LT

The expression is "True" if one of the Comparison Values meets the defined condition.

>

GT

<=

LE

>=

GE

Script variables do not have a particular data type and can include numbers and strings. Therefore, keep in mind that:

A numerical comparison is made if value contents that should be compared are numeric. It is irrelevant whether the variable has been specified in inverted commas or not.

The following condition supplies "True":

:WHILE "0" = "0"

An alpha-numeric comparison is made if non-numerical values are used.

The following condition supplies "Wrong":

:WHILE "0" = "abc"

When you compare strings, the system does not check their lengths. The following condition supplies "True" because "S" comes before the "W" in the alphabet.

:WHILE "Smith" < "Wilson"

Examples

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:

Script element Description

:IF... :ELSE... :ENDIF

Evaluate an expression and execute statements depending on the result.

Script Elements - Script Structure and Processing

About Scripts
Script Elements - Alphabetical Listing

Script Elements - Ordered by function