to:do: Question?
Jimmie Houchin
jhouchin at texoma.net
Tue Jul 9 05:00:08 UTC 2002
Hi,
Thanks for the education.
You are correct and it didn't even occur to me to use the timesRepeat.
If I am not using the index value then it seems there is no reason to
use the to:do: over timesRepeat.
I guess that should be #to:do and #timesRepeat?
I'll learn.
Thanks for sharing your knowledge.
Jimmie Houchin
Ian Piumarta wrote:
> On Mon, 8 Jul 2002, Jimmie Houchin wrote:
>
>>1 to: 10 do: [Transcript show: 'Hello World!'].
>>I get this error.
>>This block requires 0 arguments and is being evaluated with 1.
>
> Most message names that end in 'do:' are enumerators and expect their
> block to take an argument to eat up each successive value in the
> enumeration.
>
> `1 to: 10 do: [...]' is a shorthand way of enumerating over an (implicit)
> sequence of 10 integers. The mere existence of redundancy (giving
> starting and ending values) should suggest that it's more than just
> iteration (in which only the number of iterations, and not the value at
> each iteration, is important).
>
> The corresponding iterator is:
>
> 10 timesRepeat: [Transcript cr; show: 'Had enough yet?'].
>
> Ian
More information about the Squeak-dev
mailing list
|