Loop structures: Difference between revisions

Content added Content deleted
m (Katsumi a.k.a. Upperdecker2562 moved page Loop Structures to Loop structures)
Line 38: Line 38:


===doTimes===
===doTimes===
<lang ambienttalk>
<syntaxhighlight lang="ambienttalk">
// print 1 2 3 ... 20
// print 1 2 3 ... 20
20.doTimes { |i| system.print(" "+i); }
20.doTimes { |i| system.print(" "+i); }
</lang>


</syntaxhighlight>
=== each ===


===each===
Iterate over a collection:


Iterate over a collection:
<lang ambienttalk>
<syntaxhighlight lang="ambienttalk">
[ "foo", "bar", "baz" ].each: { |e|
[ "foo", "bar", "baz" ].each: { |e|
system.print(" "+e);
system.print(" "+e);
}
}
// prints: foo bar baz
// prints: foo bar baz

</lang>
</syntaxhighlight>


==[[AppleScript]]==
==[[AppleScript]]==