On Tue, 21 Sep 1999, Kevin Miller wrote:

> On Tuesday, Sept 21 1999, Sven Schulzke wrote:
> 
> > Hi, I�m new to MetaCard, just trying to set up a loop that searches
> > through a field.
> >
> > Is there a way to set the increment of a repeat loop?
> >
> > The aim is to search every 3rd line of a field for a number. I thought
> > of something like:
> >
> > put fld "schedule" into fldVar
> > repeat with i = 1 to the number of lines of fldvar >step 3 ?<
> >     repeat with j = 1 to the number of words of line i of fldVar
> >         if word j of line i of fldvar is a number then put word j of
> > line i of fldvar after hoursVar(i)
> >     end repeat
> > end repeat
> >
> >
> > Thanks for any advice
> 
> Try the line:
> 
> add 2 to i
> 
> Right before the second "end repeat"

Actually I wouldn't recommend this.  Changing the loop variable in a
repeat loop is poor technique, IMHO, because it makes it hard to
predict what's going to happen.  For example, what happens if the
number of lines is not evenly divisible by three?  Decrementing or
setting the loop variable to a fixed number is even worse because it
can easily cause an infinite loop.

Instead use:
put 1 into i
put the number of lines in fldvar into nlines
repeat while i <= nlines
  # do something with line i
  add 3 to i
end repeat

I agree that a "step" option to the repeat control structure is what
you really want, though.
  Regards,
    Scott

> Regards,
> 
> Kevin
> 
> > Sven
> 
> Kevin Miller <[EMAIL PROTECTED]> <http://www.xworlds.com/>
> Cross Worlds Computing, MetaCard Distributors, Custom Development.
> Tel: +44 (0)131 672 2909.  Fax: +44 (0)1639 830 707.
> 

********************************************************
Scott Raney  [EMAIL PROTECTED]  http://www.metacard.com
MetaCard: You know, there's an easier way to do that...

Reply via email to