Syntax
for ControlValue = StartValue to StopValue
[step increment] {
initializer statements ;
conditional expression ;
update expression ;
initializer statements ;
conditional expression ;
}
Description
The for statement is a looping statement. It runs one or more initializer statements and then evaluates the conditional expression. Use a comma to separate multiple initializer statements. If the conditional expression evaluates to true (any non-zero value), then it runs the specified statement. It runs the update expression (if present) immediately after it runs the specified statement. The for statement is terminated if the conditional expression evaluates to false (the value 0), or it encounters a break statement.
Typically, a for statement contains one initializer statement, a conditional expression, and an update expression that all operate on the same variable.
Use a statement block in the form { statement ... } to run multiple statements. One Identity recommends using a statement block for readability.
Examples
This prints the values 1,2,3,4,5:
for (x = 1; x <= 5; x++) print(x);
This prints the values 1,2,3,4,5. (Note that this example does not have an update expression and it uses a statement block):
for (x = 1; x <= 5; ) {
print(x);
x++;
}
This prints the values 1,2,3 because the break statement terminates the loop:
for (x = 1; x <= 5; x++) {
if (x > 3) break;
print(x);
}
Syntax
for (variable in expression ) statement
Description
The for statement is a looping statement. The specified expression must be an array. It runs the specified statement once for each array element, and assigns it to the specified variable in turn. The for statement terminates when the specified expression does not evaluate to an array value, either when each element of the array has been iterated, or it encounters a break statement.
Use a statement block in the form { statement ... } to run multiple statements. One Identity recommends using a statement block for readability.
Examples
This prints the values 1,2,3,4,5:
for (x in {1,2,3,4,5}) print(x);
This does not print any value, since the expression does not evaluate to an array:
for (x in "foo") print(x);
This prints the values 1,2,3 because the break statement terminates the loop:
values = {1,2,3,4,5};
for (x in values) {
if (x > 3) break;
print(x);
}
Syntax
function ( parameter = expression, ... ) { statement ... }
Syntax
if ( expression ) statement
if ( expression ) statement else statement
Description
The if-else statement is a conditional statement. It runs the specified statement if the specified expression evaluates to true (a non-zero value). If the else part is present, it runs the associated statement if the expression evaluates to false (the value 0).
Use a statement block of the form { statement ... } to run multiple statements. One Identity recommends using a statement block for readability.
Examples
Accept if the user is contained in the set of trusted users, otherwise continue execution at the next statement:
trustedusers = {"jamie","corey","robyn"};
if (user in trustedusers)
accept;
Accept if the user is contained in the set of trusted users, otherwise reject:
trustedusers = {"jamie","corey","robyn"};
if (user in trustedusers)
accept;
else
reject;
Note the use of statement block to handle multiple statements:
trustedusers = {"jamie","corey","robyn"};
if (user in trustedusers) {
print("accepted");
accept;
} else {
print("rejected");
reject;
}