GLBasic forum

Main forum => GLBasic - en => Topic started by: François Vanzeveren on 2008-Sep-06

Title: FOR and FOREACH
Post by: François Vanzeveren on 2008-Sep-06
Hello all,

In the help, I read for "FOREACH" the following
Quote
FOREACH ref in feld[]
...
NEXT

During the loop, "ref" will be a pointer (BYREF) variable to each element in the array.
You do not need to define "ref" as LOCAL.
It will be done automatcally, and it will invalid after the corresponding NEXT command.

I am wondering wether it is also the case with the "FOR" command: do we need to define the counter as LOCAL or is it done automatically?

Best regards

François
Title: Re: FOR and FOREACH
Post by: Moru on 2008-Sep-07
If I expect a local counter I would preffer to declare it local to be safe. In the current version it is declared as GLOBAL but that might change. I don't get an error message when not declaring it so I expect it to change soon :-)
Title: Re: FOR and FOREACH
Post by: François Vanzeveren on 2008-Sep-07
Thanks for this advice. I will follow it.

Note to glbasic authors: it would be helpfull to mention the LOCAL/GLOBAL status of counters for loops commands.

Regards
Title: Re: FOR and FOREACH
Post by: Kitty Hello on 2008-Sep-07
You're right. Should this be LOCAL automatically? Sounds handy.
Title: Re: FOR and FOREACH
Post by: Moru on 2008-Sep-07
Local to the for/next loop would be handy yes