Re: for puzzlement

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...
petelomax said...

Well, I never. Pre-declaring loop variables has worked for so long in phix that I forgot you cannot do that in OE.

Somebody catch me up: Why would you pre-declare your loop variables?

So you can look see how far the loop got before exiting, especially useful if it has multiple exit points, and/or if the whole point of the loop was just to set i anyway.

for i=1 to length(s) do 
    ... 
    if this then exit end if 
    ... 
    if that then exit end if 
    ... 
    if the other then exit end if 
    ... 
end for 
?i -- oops, error (unless you pre-declare it) 

The only other sensible alternative would be to pre-declare another variable say ifail and set it to i at the top of the loop, btdt.

Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu