...
The above example (somewhat contrived, see included() or subset() for a more practical solution) shows how break() can be useful when iterating over lists, if you don't need knowledge of all of the elements.
In this next example, the forEach() function will check each prefix in turn until it finds a prefix length greater than 20 at which point a debug message will be printed out to the log and break() will be called which causes the loop to stop processing.
Code Block |
---|
forEach( $prefix, lookup.prefixes, if( stringLength($prefix) > 20, do ( debug("Stopping because prefix > 20"), break() ) ), $highest = $prefix ) |
...
Note that the call to break() exits both the inner do() routine, and the outer forEach() - but not the current stream processing cycle.
...