Repeat for each loop assistance, please.

yoy yoy at comcast.net
Sun Aug 3 00:01:01 EDT 2003


Igor,

Thanks for the quick reply! I will add your code and see how it behaves.

I'm a little clueless but appreciate your help!!!

All the best,

Andy

----- Original Message ----- 
From: "Igor Couto" <igor at pixelmedia.com.au>
To: <use-revolution at lists.runrev.com>
Sent: Sunday, August 03, 2003 12:26 AM
Subject: Re: Repeat for each loop assistance, please.


> Hi there, Andy!
> 
> On Sunday, August 3, 2003, at 01:56  PM, yoy wrote:
> 
> > I have the following loop statement:
> >
> > repeat for each line gameLine in fld "gamelist"
> >
> > I need to obtain the line number for the current iteration.
> 
> If I understand the docs correctly, the 'repeat for each' form of the 
> repeat structure is best used when you need to use *only* the CONTENTS 
> of the particular container. If you need to count the loops and refer 
> to chunks of the container by number (rather than merely use the 
> chunks), then perhaps the "repeat with x = 1 to ..." form would be 
> better.
> 
> You can still get the CONTENTS when using the 'repeat with x' form:
> 
> repeat with x = 1 to the number of lines in field "gameList"
> put the text of line x of field "gameList" into lLineContent
> ...
> end repeat
> 
> 
> > I'm error
> > checking for the number of items in gameLine and if it isn't equal to 
> > 5, I
> > want to raise an answer dialog and stop the script, then hilight that 
> > line
> > in fld "gameList".
> 
> repeat with x = 1 to the number of lines in field "gameList"
> put the text of line x of field "gameList" into lGameLine
> if (the number of items in lGameLine <> 5) then
> put true into lBadItemNumberFlag
> put x into lBadLineNumber
> exit repeat
> end if
> ...
> end repeat
> if (lBadItemNumberFlag) then
> answer lMyUserWarning
> set the hilitedLine of field "gameList" to lBadLineNumber
> end if
> 
> > The other problem is that the variable might be 6 with the first 5 
> > items
> > isolated and the 6th item examined under different circumstances, ala
> > checking a lotto game with or without a bonus ball number.
> >
> 
> In this case, the check condition inside the repeat loop might look 
> something like:
> 
> if (the number of items in lGameLine <> 5) and /
> (the number of item in lGameLine <> 6)
> ...
> end if
> -- so, by the time the execution gets to this line, you know that your 
> line MUST have
> -- either 5 or 6 items in it. So:
>   if (the number of items in lGameLine = 6) then
> ... -- do whatever stuff is necessary to process the 6th item
> end if
> -- Next, you process the first 5 items, which are common to both the 5 
> and 6-item lines:
> ... -- do the common stuff here
> 
> 
> I hope this helps! There are probably better and more succinct ways to 
> do what you want, but I am a newbie, too, so my suggestion is based on 
> my limited experience as well!!!
> 
> Kind Regards,
> --
> Igor de Oliveira Couto
> ----------------------------------
> igor at pixelmedia.com.au
> ----------------------------------
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution



More information about the use-livecode mailing list