Repeat for each item - should it be more robust ?

Klaus Major klaus at major-k.de
Sun Feb 12 05:39:50 EST 2006


Hi Martin,

> Try the following script -
>
> repeat for each item tItem in "apple,banana,broccoli"
> if tItem = "broccoli" then put " - vegetable" after tItem else put " -
> fruit" after tItem
> answer tItem
> end repeat
>
> Rev answers 'apple - fruit', 'apple  - fruit' and 'broccolli -  
> vegetable'
> (There is an extra space in the second answer)
>
> I know this is messing with the repeat variable which is ill-advised,
> but I would have thought rev should be able to handle this.
> It can be fixed by using a dummy variable, eg -
>
> repeat for each item tItem in "apple,banana,broccoli"
> if tItem = "broccoli" then put tItem&" - vegetable" into x else put
> tItem&" - fruit" into x
> answer x
> end repeat

"repeat for each..." is a READ ONLY operation and modifying  
"tItem" (in your case)
may give some unexspected results as you have experienced.

And this is clearly(!) documented in the docs :-)

> regards
> Martin Blackman

Regards

Klaus Major
klaus at major-k.de
http://www.major-k.de




More information about the use-livecode mailing list