Break
See Also: Boolean Expressions, Execution Control Commands, For, Loop, Repeat, Until, While, Boolean
Purpose
Stops execution of a control block.
Syntax
Break [Begin]
What It Does
Break stops execution of a control block. A block is a Begin...End, Repeat...Until, a For...Loop, or a While...Loop construction.
Break with no argument causes execution to jump to the first command after the end of the block. A Break Begin causes execution to go back to the beginning of the scope.
Example
Procedure OnClick
Integer iCount // a counter
String sValue // contents of a string
String sTest // test character
// loop through the characters of the string 'hello world'
Move "hello world" To sValue
For iCount From 1 To (length(sValue))
Move (Mid(sValue, 1, iCount)) To sTest
// if the character 'w' is found, quit the loop.
If (sTest = 'w') Begin
Break
Else; // show progress
Showln "Character number " iCount " is a [" sTest "]"
Loop
End_Procedure
Notes
-
Note that
Breakonly exits the current block (the block executing when theBreakcommand is executed). -
The following code block is a reworking of the
For ... Loopfrom the previous example. Note that it contains an unintentional bug, because theBreakquits theBegin ... Endblock, but not theFor ... Loop:
Move "hello world" To sValue
For iCount From 1 To (length(sValue))
Move (Mid(sValue, 1, iCount)) To sTest
// If the character 'w' is found, quit the loop.
If (sTest = 'w') Begin
Showln "found a 'w'"
Break
//
// BUG!
// The break quits the begin…end, not the for…loop,
// so all the characters in the string will print.
End
Else; // show progress
Showln "Character number " iCount " is a [" sTest "]"
Loop