Loops/Downward for: Difference between revisions

Content deleted Content added
Line 1,815: Line 1,815:
Thus the first variant is one message send (aka virtual function call) to the number, whereas the second is two message sends and an object instantiation.
Thus the first variant is one message send (aka virtual function call) to the number, whereas the second is two message sends and an object instantiation.


The nice thing with Intervals is that they can be concatenated with a <tt>","</tt> operator (like all collections); thus, I could als write:
The nice thing with Intervals is that they can be concatenated with a <tt>","</tt> operator (like all collections); thus, I could also write:
<lang smalltalk>(10 to: 6 by: -1),(1 to: 5) do:[:aNumber |
<lang smalltalk>(10 to: 6 by: -1),(1 to: 5) do:[:aNumber |
aNumber displayNl.
aNumber displayNl.
]</lang>
]</lang>
to enumerate in a different order,
to enumerate in a different order,
or combine ranges with a constant array:
<br>or combine ranges with a constant array:
<lang smalltalk>(10 to: 2 by: -2),#(99 999),(1 to: 10 by: 2) do:[:aNumber |
<lang smalltalk>(10 to: 2 by: -2),#(99 999),(1 to: 10 by: 2) do:[:aNumber |
aNumber displayNl.
aNumber displayNl.