to:do: Question?
Ian Piumarta
ian.piumarta at inria.fr
Tue Jul 9 03:43:31 UTC 2002
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
|