Loops/Foreach: Difference between revisions

Line 2,382:
Most modern Smalltalks allow for a selector symbol to be sent a <tt>value:</tt> message; which allows for the very compact:
<lang smalltalk>aCollection do:#displayNl.</lang>
 
(and because Aikido mentions it: of course this works for any kind of collection (and even things which simply implement a <tt>do:</tt> method to iterate on something)
<lang smalltalk>(1 to:5 by:10) do:#displayNl.
'hello foobar' do:#displayNl.
(Integer primesUpTo:100) do:#displayNl.
'.' asFilename directoryContents do:#displayNl.
Smalltalk allClasses do:#displayNl.
etc.</lang>
 
=={{header|Snabel}}==
Anonymous user