I've just been observing other people's code, and from time to time i see this "do" statement completely alone. Does this statement have any additional meaning to it? What exactly is it used for?
Example:
do
print("Code")
end
I've just been observing other people's code, and from time to time i see this "do" statement completely alone. Does this statement have any additional meaning to it? What exactly is it used for?
Example:
do
print("Code")
end
The "do" keyword can be used to create new scopes in code. Basically used for making a new environment for holding local variables, incase you don't want to make a new one.
Here's an example:
do
local test = "hello"
print(test) -- hello
end
print(test) -- nil
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
You could also explain do while to him.
Not needed. It's the do statement that creates a new scope for "while" and completes it. The "while" loop would be an entirely different topic.
Lua doesn't have
do while, it hasrepeat until. This is also to hide variables so that you can keep things private in an implementation (modulescripts obviate this though)I think he was referring to the while loop, just ordered it wrong.