Loops/Foreach: Difference between revisions

Content added Content deleted
Line 2,384: Line 2,384:


(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)
(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.
<lang smalltalk>(1 to:6 by:2) do:#transcribeCR.
'hello foobar' do:#displayNl.
'hello' do:#transcribeCR.
(Integer primesUpTo:100) do:#displayNl.
(Integer primesUpTo:100) do:#transcribeCR.
'.' asFilename directoryContents do:#displayNl.
'/' asFilename directoryContents do:#transcribeCR.
Smalltalk allClasses do:#displayNl.
((Smalltalk allClasses collect:#name) asSortedCollection to:2) do:#transcribeCR.

funnyClassLessObject := Plug new
respondTo:#do:
with:[:arg |
arg value:'look ma'.
arg value:'no classes needed'].
funnyClassLessObject do:#transcribeCR.
etc.</lang>
etc.</lang>
{{out}}
1
3
5
h
e
l
l
o
2
3
5
...
97
home
usr
...
tmp
cores
AAAARecord
AATree
look ma
no classes needed


=={{header|Snabel}}==
=={{header|Snabel}}==