lua-users home
lua-l archive

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


Yes, each time you enter a conditional block, do-block, or loop, you can declare variables that will go out of scope at the end of that block. Bonus fact: the iteration variables in for loops in lua go out of scope between iterations of the loop.
 :
If you are familiar with _javascript_, I believe this is the same as _javascript_'s let and const, and Python's behavior is the same as _javascript_'s var.

thank you very much for pointing that out - I was mislead by the reference manual which discuss scopes by using only do...end statements - in fact I was under the impression that scopes were created only at the function definition (kind of _javascript_'s var) and at do...end blocks (kind of curly braces in other languages).

Now forgive me for asking this, even if I am a programmer I am not a Computer Science Engineer. My question is: why are new scopes created by "if", "for" and other statements and not only by function definitions and do...end statements? If one wanted a new scope one could easily type "do" (as in other languages we just open a curly brace). So why this is done implicitly? What is the advantage or the theoretical reason? Again forgive me for this maybe silly question - remember my background is not in computer science.

(and again: I am not suggesting to change anything in Lua - I am just curious about the reason why things are as they are - there may be historical reason, or they me practical reasons - I am perfectly fine and just want to learn more).

   Andrea

--
Andrea Vitali






_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org