The break statements, leave and restart may be used to terminate the execution of a pattern or singular object or to start execution from the beginning:
Ptn: Super
...
leave(Ptn)
...
restart(Ptn)
...
Obj: obj Super
...
leave(Obj)
...
restart(Obj)
...
Leave and restart may appear at an arbitrary nesting level within Ptn
or Obj
.
Note. The declarations are only executed when the object is generated — a restart does not imply re-execution of declarations within Ptn and/or Obj.
Example
Loop: do
i: var integer
i := i + 1
foo(i)
if (i > 10) :then leave(Loop)
bar
restart(Loop)
Comparison to Beta
In Beta a statement may be labelled – qBeta does not have labelled statements. Instead singular objects may be used as labelled statements.
OBS! Introduce the do-object
Grammar
<Break-Statement> ::= <Leave-Statement> | <Restart-Statement>
<Leave-Statement> ::= 'leave' '(' <Pattern-or-Object-name> ')'
<Restart-Statement> ::= 'restart' '(' <Pattern-or-Object-name> ')'