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


funnyClassLessObject := Plug new
funnyClassLessObject := Plug new
Line 2,395: Line 2,395:
arg value:'look ma'.
arg value:'look ma'.
arg value:'no classes needed'].
arg value:'no classes needed'].
funnyClassLessObject do:#transcribeCR.
funnyClassLessObject do:#displayNl.
etc.</lang>
etc.</lang>
{{out}}
{{out}}