1. Fool newbie question

G'day all

Using a "for" loop to look at each element of a sequence, e.g.
   for i = 1 to length(seq)
is the results of length(seq) re-evaluated for each pass thru the loop? Two
reasons for asking:

1.  if so, then

    x = length(seq)
    for i = 1 to x

    would be more "efficient"??

2.  shortening / truncating the sequence in one of the loops will
    stop the loop?? Or just crash and burn when trying to reference
    the now nonexistent part of the original sequence??

TIA

Regards
Tony

new topic     » topic index » view message » categorize

2. Re: Fool newbie question

Tony Bucholtz wrote:

> Using a "for" loop to look at each
> element of a sequence, e.g.
>    for i = 1 to length(seq)
> is the results of length(seq) re-evaluated
> for each pass thru the loop?

No; here's a demonstration:

   sequence s
   s = "1"
   for i = 1 to length( s ) do
      s &= "2"
   end for
   puts( 1, s )

If it was re-evaluated each time, you'de be in an endless loop.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: Fool newbie question

G'day all

David, thanks for that - I hadn't thought of the reverse case (a growing
sequence)

Regards
Tony

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu