🌳Loop mode
Starting from v2.9.0, LiteFlow provides loop expression syntax.
# FOR
The FOR loop expression is used for a fixed number of loops. The usual usage is:
<chain name="chain1">
FOR(5).DO(THEN(a, b));
</chain>
The above expression means that a->b loops 5 times.
If you are not sure how many times to loop when you define the rule, you can also define it like this:
<chain name="chain1">
FOR(f).DO(THEN(a, b));
</chain>
The f node needs to be For Component
, and returns an int loop count. For how to define it, please refer to For component.
# WHILE
The WHILE loop expression is used for conditional looping and is usually used as:
<chain name="chain1">
WHILE(w).DO(THEN(a, b));
</chain>
The w node needs to be While component
and returns a boolean value. If it is true, the loop will continue. For how to define it, please refer to While component.
# BREAK
LiteFlow also supports the BREAK syntax, which means break out of the loop.
The BREAK keyword can be followed by FOR and WHILE, and is usually used as follows:
<chain name="chain1">
FOR(f).DO(THEN(a, b)).BREAK(c);
</chain>
<chain name="chain1">
WHILE(w).DO(THEN(a, b)).BREAK(c);
</chain>
The c node needs to be Break component
, returning a boolean value, and exiting the loop if true. For how to define it, please refer to Break component.