Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What exactly is the "do" keyword for?

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

1 answer

✓ Accepted answer

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

4 comments

0

You could also explain do while to him.

0

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.

0

Lua doesn't have do while, it has repeat until. This is also to hide variables so that you can keep things private in an implementation (modulescripts obviate this though)

0

I think he was referring to the while loop, just ordered it wrong.

This discussion is preserved as it was. New answers, comments, and votes are closed.