Description
The break statement exits a loop and terminates cases. Use to force an immediate exit in case statements and looping statements such as for, while, and do-while statements.
Example
for ( oneuser in userlist )
{
if (oneuser == "root")
{
break;
}
print(oneuser);
}
Description
Use the continue statement in the body of a C-style for loop, while, or do-while statement to skip the rest of the statements in the body of the loop and start again from the top of the loop.
Example
for ( oneuser in userlist )
{
if (oneuser == "root")
{
continue;
}
print(oneuser);
}
Syntax
dostatement while ( expression ) ;
Description
The do-while statement is a looping statement. It repeatedly runs the specified statement until the specified expression evaluates to false (the value 0) or it encounters a break statement.
The specified statement runs at least once (unlike the while statement, which may terminate immediately).
Use a statement block in the form { statement ... } to run multiple statements in the loop. One Identity recommends using a statement block for readability.
Examples
This prints the values 1,2,3,4,5:
x=1;
do print(x++); while (x <= 5);
This prints the values 1,2,3,4,5 using a statement block:
x = 1;
do {
print(x);
x++;
} while (x <= 5);
This prints the values 1,2,3 because the break statement terminates the loop:
x=1;
do {
if (x > 3) break;
print(x++);
} while (x <= 5);
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);
}