...
Excerpt | ||
---|---|---|
| ||
break() Within a do() or forEach() function break() causes the function loop to stop immediately and return a _NULL. |
Function: break()
Within a do() or forEach() function, The break() function causes the do() or forEach() functions function to stop immediately and return a _NULL value. $-variables in the environment of the forEach() or do() that were in scope directly before break() was called will still be available after the call to break().
If used outside of a do() or forEach() function then break() will cause the analysis for the Stream Set to stop as though a stop() function was called (but will produce an error message rather than a warning message). No records will be saved for that Stream Set.If used inside of a do() or forEach() function that is itself nested inside of another do() or forEach() function, break() will only exit the inner (nested) function call. The outer expression will continue to be evaluated in the usual way.
The break() function should only be used within a forEach().
Syntax
break()
Examples
In this first example, forEach() is used to iterate over a list of manager names until "Wally" is found, at which point we can stop looking. Used in a string-valued field on a streamattribute, this would output the value "Found Wally!" into the stream table record in that field.
Note how $outputString is still available after the call to break() has been made and the do() routine has terminated.
Code Block |
---|
do( $outputString = "Can't find Wally..." forEach($manager, $managersList if($manager = "Wally", do( $outputString "Found Wally!" break() ) ) ), //output the result $outputString ) |
...
Code Block |
---|
forEach( $prefix, lookup.prefixes,
if( stringLength($prefix) > 20,
do (
debug("Stopping because prefix > 20"),
break()
)
),
$highest = $prefix
) |
...
) |
...