| | 406 | |
| | 407 | =head1 The goto statement |
| | 408 | |
| | 409 | In addition to C<next>, C<last>, and C<redo>, Perl 6 also supports |
| | 410 | C<goto>. As with ordinary loop controls, the label is searched for |
| | 411 | first lexically within the current subroutine, then dynamically outside |
| | 412 | of it. Unlike with loop controls, however, scanning a scope includes |
| | 413 | a scan of any lexical scopes included within the current candidate |
| | 414 | scope. As in Perl 5, it is possible to C<goto> into a lexical scope, |
| | 415 | but only for lexical scopes that require no special initialization |
| | 416 | of parameters. (Initialization of ordinary variables does not |
| | 417 | count--presumably the presence of a label will prevent code-movement |
| | 418 | optimizations past the label.) So, for instance, it's always possible |
| | 419 | to goto into the next case of a C<when> or into either the "then" |
| | 420 | or "else" branch of a conditional. You may not go into a C<given> |
| | 421 | or a C<for>, though, because that would bypass a formal parameter |
| | 422 | binding (not to mention list generation in the case of C<for>). |
| | 423 | (Note: the implicit default binding of an outer $_ to an inner $_ |
| | 424 | can be emulated for a bare block, so that doesn't fall under the |
| | 425 | prohibition on bypassing formal binding.) |