Loops/Foreach: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 582:
<lang perl6>say $_ for @collection;</lang>
 
Perl 6 leaves off the "<tt>each"</tt> from <tt>foreach</tt>., Insteadleaving youus can just usewith <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>
for @collection.kv -> $key, $value {}
</lang>
 
You can also browse an array by multiple values at a time if you place a list after the <tt>-></tt>
 
=={{header|PHP}}==
Anonymous user