In Control flow§
See primary documentation in context for proceed and succeed
Both proceed
and succeed
are meant to be used only from inside when
or default
blocks.
The proceed
statement will immediately leave the when
or default
block, skipping the rest of the statements, and resuming after the block. This prevents the when
or default
from exiting the outer block.
given *"This says".say;
This is most often used to enter multiple when
blocks. proceed
will resume matching after a successful match, like so:
given 42# OUTPUT: «Int»# OUTPUT: «42»
Note that the when 40..*
match didn't occur. For this to match such cases as well, one would need a proceed
in the when 42
block.
This is not like a C
switch
statement, because the proceed
does not merely enter the directly following block, it attempts to match the given
value once more, consider this code:
given 42# OUTPUT: «Int»# OUTPUT: «42»
...which matches the Int
, skips 43
since the value doesn't match, matches 42
since this is the next positive match, but doesn't enter the default
block since the when 42
block doesn't contain a proceed
.
By contrast, the succeed
keyword short-circuits execution and exits the entire given
block at that point. It may also take an argument to specify a final value for the block.
given 42# OUTPUT: «Int»
If you are not inside a when or default block, it is an error to try to use proceed
or succeed
.Also remember, the when
statement modifier form does not cause any blocks to be left, and any succeed
or proceed
in such a statement applies to the surrounding clause, if there is one:
given 42# OUTPUT: «This saysThis says tooAnd this saysThis also says»