On 15/11/00 3:49 pm, Gregory Lypny <[EMAIL PROTECTED]> wrote:

> Hi Everyone,
> 
> Can the "for each" form of the repeat structure be used to transform
> one itemized list into another?
> 
> For example, if variable X = 2, 4, 6, I'd like to create variable Y
> as the square of the items of X, so that Y = 4, 16, 36.
> 
> I tried doing this:
> 
> Repeat for each item i in X
> put i^2 into item i of Y
> end repeat
> 
> But what I get is a long list of commas (empty items) and a single
> number at the end (36).

In that repeat loop, the variable "i" contains the *contents* of each item
in the variable x, rather than the item number.  So as you go down the loop,
it is run each time as:

put 2^2 into item 2 of y
put 4^2 into item 4 of y
put 6^2 into item 6 of y

What you need to write instead is:

put i^2 & comma after Y
end repeat
delete last char of y --strip trailing comma

Regards,

Kevin

> Any thoughts on this?
> 
> Regards,
> 
> Greg

Kevin Miller <[EMAIL PROTECTED]> <http://www.runrev.com/>
Runtime Revolution Limited (formerly Cross Worlds Computing).
Tel: +44 (0)131 672 2909.  Fax: +44 (0)1639 830 707.


Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to