Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with FOR .. ENDFOR
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00396797
Message ID:
00396799
Views:
13
>I have a FOR loop, FOR i=1 TO aval,
>within the loop, a function gets called that also has a FOR loop,
> FOR i=1 TO anotherval.
>Basicly
>procedure parent_loop
>for i=1 to aval
> stuff
> =my_funct()
>endfor
>
>procedure my_funct
> for i=1 to anotherval
> do stuff
> endfor
>
>Much to my suprise, the i in the calling function gets its value reset by the called function.
>Is this behaviour by design, or what? I had thought that the inner i would be out of scope for the outer

I believe variables are Private unless declared otherwise. Private variables are in scope for called procedures.

You need to declare the i variables local in both procedures. Put:

Local i

in both procedures and it should fix your problem. Just to be safe though I would use another counter in the second procedure like j.
Rip Ryness
International Falls, MN
Previous
Reply
Map
View

Click here to load this message in the networking platform