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