[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error Loop Variable cannot be global


Just write it like this:

Public $vList As String[] = ["a", "b", "c"]

Public Sub Main()
Dim $vStr As String

  For Each $vStr In $vList
    Debug $vStr
  Next

End

If you use variables with wider scope in loops, you will quickly end up
with nasty bugs. Consider a situation where subs/functions happen to use
the same variable in a loop --> bug.
Or if each of them use the variable only once, then what's the point of the
global scope! I see no good use for that. Thus I think it should be
forbidden.


Jussi

References:
Error Loop Variable cannot be global"Mayost Sharon" <sharon@xxxxxxxxx>