Loops/Foreach: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
SqrtNegInf (talk | contribs) m →{{header|Raku}}: Fix comments: Perl 6 --> Raku |
||
Line 2,049: | Line 2,049: | ||
{{works with|Rakudo|2015.10-40}} |
{{works with|Rakudo|2015.10-40}} |
||
<lang perl6>say $_ for @collection;</lang> |
<lang perl6>say $_ for @collection;</lang> |
||
Raku leaves off the <tt>each</tt> from <tt>foreach</tt>, leaving us with <tt>for</tt> instead. The variable <tt>$_</tt> refers to the current element, unless you assign a name to it using <tt>-></tt>. |
|||
<lang perl6>for @collection -> $currentElement { say $currentElement; }</lang> |
<lang perl6>for @collection -> $currentElement { say $currentElement; }</lang> |
||
Raku will do it's best to put the topic at the right spot. |
|||
<lang perl6>.say for @collection; |
<lang perl6>.say for @collection; |
||
for @collection { .say };</lang> |
for @collection { .say };</lang> |