What does "local x do" do?

So, I’ve seen this not much but atleast 3 times.

local x do

end

What does it mean? If any examples is shown then thanks!

1 Like

If the code is formatted correctly, it would be:

local x
do

end

The variable x isn’t important, but everything under it is important.
The do keyword simply runs anything inside of it.

while task.wait() do

end

If a while or for loop is attached to the do, it will repeat whatever is inside it multiple times.

1 Like

Oh, so it kinda acts like while wait do loops?
The “do” means its gonna loop foreever orr?

what is the difference between

do
print("Hello")
end

and

print("Hello")

What would do end be useful for? I’m just curious too because it doesn’t seem to hold any relevance besides loops.

Not exactly. The do runs everything inside it only once. If you attach a loop to that do, it will run it multiple times.

There is no difference between using it or not.

1 Like

local is used to declare a variable only used in that certain script.

do is used to run a code snippet while being able to be collapsed. Any variables declared inside that do statement can not be used outside of the statement. So it’s basically declaring a function and running it at the same time.

local x do is one of the practices in scripting which is designed if you want to do something for x before x will be used for anything, such as giving pre-determined variables for x as a table.
And having the feature, that the statement is collapsable, included will make your scripts fundamentally more readable.

this is a formatting paradigm that’s rather old. it doesn’t have any functionality, though in some cases it can be optimized since memory is freed after a scope is exited.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.