Script Statement: Defines a loop in which scripting parts can be executed several times.
: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". |
The :WHILE statement is a control structure that can be used to process parts of a scriptA particular Automation Engine object type. 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 variableIt stores or retrieves values dynamically at runtime. An individual Automation Engine object type. 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"
The following example requests a userIn the Automation Engine, a user is an instance of a User object, and generally the user is a specific person who works with Automic products. The User object is assigned a user ID and then a set of access rights to various parts of the Automation Engine system and product suite. These access rights come in the form of Automation Engine authorizations and privileges, Decision user roles and EventBase rights and ARA web application object rights. You can manage all these centrally in the ECC user management functions. See also, Unified user management. to enter a name and a departmentDepartment name to which the Automation Engine user belongs.. 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 |
---|---|
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
Automic Documentation - Tutorials - Automic Blog - Resources - Training & Services - Automic YouTube Channel - Download Center - Support |
Copyright © 2016 Automic Software GmbH |