@@ -397,12 +397,6 @@ as though the rest of the statements in the block are skipped.
397
397
A C < when > statement will also do this (but a C < when > statement modifier
398
398
will I < not > .)
399
399
400
- given 42 {
401
- "This says".say when 42; # just a prettier 'if $_ ~~ Int'
402
- when Int { "This also says".say };
403
- "This never says".say;
404
- }
405
-
406
400
In addition, C < when > statements C < smartmatch > the topic (C < $_ > ) against
407
401
a supplied expression such that it is possible to check against values,
408
402
regular expressions, and types when specifying a match.
@@ -424,6 +418,20 @@ C<when> statements. The following code says C<"Int"> not C<42>.
424
418
}
425
419
#-> Int
426
420
421
+ When a C < when > statement or C < default > statement causes the outer
422
+ block to return, nesting C < when > or C < default > blocks do not count
423
+ as the outer block, so you can nest these statements and still
424
+ be in the same "switch" just so long as you do not open a new block:
425
+
426
+ given 42 {
427
+ when Int {
428
+ when 42 { say 42 }
429
+ say "Int"
430
+ }
431
+ default { say "huh?" }
432
+ }
433
+ #-> 42
434
+
427
435
= head3 X < proceed and succeed|control flow,proceed succeed >
428
436
429
437
Both C < proceed > and C < succeed > are meant to be used only from inside C < when >
@@ -486,6 +494,22 @@ specify a final value for the block.
486
494
}
487
495
#-> Int
488
496
497
+ If you are not inside a when or default block, it is an error to try
498
+ to use C < proceed > or C < succeed > . Also remember, the C < when > statement
499
+ modifier form does not cause any blocks to be left, and any C < succeed >
500
+ or C < proceed > in such a statement applies to the surrounding clause,
501
+ if there is one:
502
+
503
+ given 42 {
504
+ { say "This says" } when Int;
505
+ "This says too".say;
506
+ when * > 41 {
507
+ { "And this says".say; proceed } when * > 41;
508
+ "This never says".say;
509
+ }
510
+ "This also says".say;
511
+ }
512
+
489
513
= head2 X < loop|control flow >
490
514
491
515
The C < loop > statement is the C-style C < for > loop in disguise:
0 commit comments