I was just thrown by the example with 'If 1' always true.
If you change to 'If 0' and use EnableExplicit then I am curious why no error?
Maybe look to the ASM to see that all procedure variables are declared regardless of condition?
Shield wrote:The code shown by BorisTheOld will of course be invalid since variables
are passed down the scopes and cannot be redefined.
In PB they can be redefined though. Also, without EnableExplicit a variable is declared on its first use. Both of these rules do not fit well with this kind of block scoping.
Yes, that was my point - we're talking about PB and BASIC.
I was expressing the opinion that it's a bad idea to allow local scope within If/EndIf blocks and similar constructs. I've seen this type of usage in other languages and the aftermath is not something one would wish to debug.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Well they can be redefined now, that behavior obviously has to go if this feature gets implemented.
I didn't realize they can be "defined" again, because I never did this (why should I?). IMHO, this shouldn't
even be possible and since types can't be changed, I guess the keyword just gets ignored the second
time it is used.
The second part seems to be a valid point though (however, I always use EnableExplicit).
You can use Protected / Define / Global multiple times on the same variable without getting an error message.
Most other languages I know will throw an error if there is an attempt to redefine a variable.
For some reason I didn't check protected, but it doesn't throw an error with Define / Global.
Arguably it does make sense to allow that for Shared / Global usage, even though that's
very likely bad programming practice in most cases.
IMHO, it there is no benefit. However, perhaps someone likes using variable named (such as i) for every single For-loop that has no significance in the var name... that would be the only reason (as bad as it may be) that I can think of.