Author Topic: FOR and FOREACH  (Read 2020 times)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
FOR and FOREACH
« 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

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: FOR and FOREACH
« Reply #1 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 :-)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: FOR and FOREACH
« Reply #2 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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10708
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FOR and FOREACH
« Reply #3 on: 2008-Sep-07 »
You're right. Should this be LOCAL automatically? Sounds handy.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: FOR and FOREACH
« Reply #4 on: 2008-Sep-07 »
Local to the for/next loop would be handy yes