continue
continue keyword skips an iteration.
Purpose
A side statement for skipping an iteration.
Context
Rule actions or functions
Syntax
continue;
Description
Use the continue statement
in the action part of a rule and in a function to skip an iteration
of a while or for loop. This statement
forces the rule engine to skip to the next test of the loop statement.
Example
The rule StockDropWarning checks
the percent change of a customer’s stocks and issues a warning if
a stock price dropped by more than a certain percentage. The condition Client returns
an account number in variable ?a and a decimal value percentWarningMark in
variable ?p. The second condition, ClientStockList,
returns a stock list in variable ?s corresponding
to the account number equal to ?a. In the action
part of the rule, the while statement iterates over
every stock in the stock list ?s. If a stock type
is equal to LONG, the continue statement
cause the iteration to skip the rest of the statements in the while block
and proceed to the while test. If a stock type is
not equal to LONG, the difference between the purchase
price and the current price is calculated. If the stock price decreased
in ?p percent below the purchasePrice,
a message is printed.
rule StockDropWarning {
when {
?c:Client(?a:account_number;?p:percentWarningMark);
ClientStockList(account_number == ?a; ?s:stockList);
}
then {
Enumeration ?enum = ?s.elements();
while (?enum.hasMoreElements()) {
Stock ?x = (Stock)enum.nextElement();
if (?x.type == Stock.LONG)
continue;
if ( ((1.-?p)*?x.purchasePrice) > ?x.currentPrice ) {
System.out.println("Dear "+ ?c.name + " Your stock "
+ ?x.ticker + " has dropped " +
((?x.purchasePrice - ?x.currentPrice) /
?x.purchasePrice ) + " percent.");
}
}
}
};