Anonymous user
Conditional structures: Difference between revisions
→{{header|Perl 6}}: add missing stuff
(→{{header|friendly interactive shell}}: Creation of fish example) |
(→{{header|Perl 6}}: add missing stuff) |
||
Line 2,531:
=={{header|Perl 6}}==
===if/else===
<
<li> All the parentheses are now optional.
</li><li> <
</li><li> If the block of an <
<lang perl6>if won() -> $prize {
say "You won $prize.";
}</lang>
If an <
===given/when===
Switch structures are done by topicalization and by smartmatching in Perl 6. They are somewhat orthogonal, you can use a <tt>given</tt> block without <tt>when</tt>, and vice versa. But the typical use is:
<code>when</code> blocks are now allowed "in any block that sets <code>$_</code>, including a▼
<lang perl6>given lc prompt("Done? ") {
<code>for</code> loop (assuming one of its loop variables is bound to <code>$_</code>)▼
when 'yes' { return }
or the body of a method (if you have declared the invocant as <code>$_</code>)." See [http://perlcabal.org/syn/S04.html#Switch_statements Synopsis 4].▼
when 'no' { next }
default { say "Please answer either yes or not." }
The ternary operator now looks like this:▼
}</lang>
▲<
▲or the body of a method (if you have declared the invocant as <
There are also statement modifier forms of all of the above.
===Ternary operator===
<lang perl6>$expression ?? do_something !! do_fallback</lang>
===Other short-circuiting operators===
<
=={{header|PHP}}==
|