Posted 24 October 2013 - 09:29 PM
I saw a bunch of scattered definitions of code blocks and local variables over the tutorials section, so I decided to put my own here.
Note that I never stated while or for, simply because do is the main word to start the block. for or while by themselves cannot start a block, but do can.
Being in scope means the variable can be read and written to.
Some examples are as follows:
(coming soon)
Another note from the PIL is:
This is all I had time to write tonight, make sure to leave (constructive) criticism on the tutorial! MUCH more content and details will be coming soon1.
Sources: http://www.lua.org/pil/4.2.html, Personal Experience
1 Soon is not guaranteed to be any particular time…
Spoiler
The definition from the PIL is as follows:In Lua, all blocks (excluding repeat) end with an "end", as opposed to many other languages who use curly braces or indentation to build blocks.Programming In Lua said:A block is the body of a control structure, the body of a function, or a chunk (the file or string with the code where the variable is declared).
Spoiler
Blocks in Lua can start with consist of:- do
- if
- repeat
Note that I never stated while or for, simply because do is the main word to start the block. for or while by themselves cannot start a block, but do can.
Spoiler
Local variables are variables that are only in scope in their own block.Being in scope means the variable can be read and written to.
Some examples are as follows:
(coming soon)
Another note from the PIL is:
Programming In Lua said:It is good programming style to use local variables whenever possible. Local variables help you avoid cluttering the global environment with unnecessary names. Moreover, the access to local variables is faster than to global ones.
This is all I had time to write tonight, make sure to leave (constructive) criticism on the tutorial! MUCH more content and details will be coming soon1.
Sources: http://www.lua.org/pil/4.2.html, Personal Experience
1 Soon is not guaranteed to be any particular time…