Loops/Downward for: Difference between revisions
Content deleted Content added
m →{{header|Smalltalk}}: format |
|||
Line 1,814: | Line 1,814: | ||
The first one sends a <tt>"to:by:do:"</tt> message to the Integer 10, passing "0", "-1", and the closure as arguments. There (in the integer), the counting and closure invokation takes place (who cares how it does it?). |
The first one sends a <tt>"to:by:do:"</tt> message to the Integer 10, passing "0", "-1", and the closure as arguments. There (in the integer), the counting and closure invokation takes place (who cares how it does it?). |
||
The second example first instantiates a range-collection object (called Interval in Smalltalk) with the <tt>"to:by:"</tt> message (sent to the integer), and then this Interval object gets a <tt>"do:"</tt> message.<br>Which - like all collections - enumerates its elements, in this case [10.. |
The second example first instantiates a range-collection object (called ''Interval'' in Smalltalk) with the <tt>"to:by:"</tt> message (sent to the integer), and then this Interval object gets a <tt>"do:"</tt> message.<br>Which - like all collections - enumerates its elements, in this case [10..0]. |
||
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. |