repeat with each

Mark Schonewille m.schonewille at economy-x-talk.com
Mon Sep 22 09:13:05 EDT 2014


Hi Larry,

The variable thisWord contains a copy of the item in the field. It 
doesn't refer to the actual item. When you put "," after thisWord, you 
change the string that is stored in variable thisWord, but not the 
string that is stored in field justOne. If you want to change the 
contents of the field, you need to create an updated copy and replace 
the contents of the field with the copy, like this:

repeat for each word myWord in field "Just One"
   put thisWord & comma after myNewdata
end repeat
sort items of myNewData
put char 1 to -2 of myNewData into field "Just One"

If you want to refer the items of the field directly, you can use repeat 
with:

repeat with x = 1 to number of words of field "Just One" - 1
   put comma after word x of field "Just One"
end repeat
sort items of field "Just One"

I could imagine that the following may work too:

replace space with comma & space in field "Just One"
sort items of field "Just One"

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Installer Maker for LiveCode:
http://qery.us/468

Buy my new book "Programming LiveCode for the Real Beginner" 
http://qery.us/3fi

LiveCode on Facebook:
https://www.facebook.com/groups/runrev/

On 9/22/2014 15:04, larry at significantplanet.org wrote:
> Hello,
>
> I have never been able to understand how to use the each form in a repeat statement.
>
> Can anyone explain why this code does not work?  It is almost verbatim from the example in the LC dictionary.
>
> on mouseUp
>
> repeat for each word thisWord in field justOne
>
> put "," after thisWord
>
> end repeat
>
> sort items of field justOne
>
> end mouseUp
>
>
>
> It does not insert the commas.  Supposedly the each form is a lot faster than using
>
> "put x + 1 into x"
> "put "," after word x of field justOne
>
> Thanks,
> Larry





More information about the use-livecode mailing list