Hello,

The output of the code below:


a := OrderedCollection new.

1 to: 3 do: [:number |
        a add: [number printString printNl].
].

(a at: 1) value.
(a at: 2) value.
(a at: 3) value.


is:


'4'
'4'
'4'


I would expect it to be:


'1'
'2'
'3'


I modified the code like this:


a := OrderedCollection new.

1 to: 3 do: [:number |
        | tempNumber |
        
        tempNumber := number.
        
        a add: [tempNumber printString printNl].
].

(a at: 1) value.
(a at: 2) value.
(a at: 3) value.


And I now get my expected value.

What is the logic here? Is there a more elegant way that you would suggest
to get the expected output?

-----
Canol Gökel
-- 
View this message in context: 
http://forum.world.st/I-get-an-output-I-wouldn-t-expect-tp2537546p2537546.html
Sent from the Gnu mailing list archive at Nabble.com.

_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to