break
break keyword exits a loop.
Purpose
A side statement for exiting a loop.
Context
Functions or technical rule actions
Syntax
break;
Description
The break statement
is used in the action part of a rule or in functions. Use it to exit
a while loop or a for loop. This
statement forces the rule engine to go to the end of the containing
statement block and to continue to the next instruction.
Example
The AlarmSurveillance rule
tests for a new Alarm object and loops while the
state is equal to ON unless the level is equal to 3.
The single rule condition matches an object Alarm if
the field state equals the static value NEW.
If such a Alarm object is matched, the engine can
execute the action part. The modify statement is
used to change the field state from NEW to ON.
The while statement is used to loop as long as the
field state has the value ON. An if statement
tests the field level. If the level is
equal to 3, a break statement is
executed and the program exits the while loop.
rule AlarmSurveillance {
when {
?a: Alarm(state == NEW);
}
then {
modify ?a {
state = ON;
}
while (?a.state == ON ) {
...
if (?a.level == 3)
break;
}
}
};