Loops/Foreach: Difference between revisions

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)
<lang smalltalk>(1 to:6 by:2) do:#transcribeCRdisplayNl.
'hello' do:#transcribeCRdisplayNl.
(Integer primesUpTo:100) do:#transcribeCRdisplayNl.
'/' asFilename directoryContents do:#transcribeCRdisplayNl.
((Smalltalk allClasses collect:#name) asSortedCollection to:2) do:#transcribeCRdisplayNl.
 
funnyClassLessObject := Plug new
Line 2,395:
arg value:'look ma'.
arg value:'no classes needed'].
funnyClassLessObject do:#transcribeCRdisplayNl.
etc.</lang>
{{out}}
Anonymous user