Hello, When I select this part: 1 to: 100 do: [:i | Transcript show: i asString; cr ]. And do print it. I only see 1 where I expected to see all the numbers from 1 till 100. What went wrong ? Roelof
Hello, You should open Transcript, and than do it, instead of print it. Mark 2014-03-30 14:45 GMT+03:00 Roelof Wobben <r.wobben@home.nl>:
Hello,
When I select this part:
1 to: 100 do: [:i | Transcript show: i asString; cr ].
And do print it.
I only see 1 where I expected to see all the numbers from 1 till 100.
What went wrong ?
Roelof
Or you may even print it, and the result (numbers from 1 to 100) will appear in Transcript window. 2014-03-30 14:48 GMT+03:00 Mark Rizun <mrizun@gmail.com>:
Hello,
You should open Transcript, and than do it, instead of print it.
Mark
2014-03-30 14:45 GMT+03:00 Roelof Wobben <r.wobben@home.nl>:
Hello,
When I select this part:
1 to: 100 do: [:i | Transcript show: i asString; cr ].
And do print it.
I only see 1 where I expected to see all the numbers from 1 till 100.
What went wrong ?
Roelof
On 30 Mar 2014, at 1:45 , Roelof Wobben <r.wobben@home.nl> wrote:
Hello,
When I select this part:
1 to: 100 do: [:i | Transcript show: i asString; cr ].
And do print it.
I only see 1 where I expected to see all the numbers from 1 till 100.
What went wrong ?
Roelof
"print it" prints the return value of the expression. In the above case, that is the return value of the to:do: method, which is the receiver, so 1 is printed. (If you read the implementation of to:do: on Number, youâll see there is no explicit return using ^ , in such cases the return is always the receiver) If you wanted to print a list of 1 .. 100 (which would be printed with print it), youâd use a method which returns such a collection for example collect:; (1 to: 100) collect: [:each | each ]. The () are needed, since there is no to:collect: method, so instead we send collect: to an interval, which we create using 1 to: 100. Cheers, Henry
participants (3)
-
Henrik Johansen -
Mark Rizun -
Roelof Wobben