The main thing a block does is keep variables in it from being defined outside of it. In this example, x is outside the block, so it can be used inside or outside of it, but if you were to do
do
local x = 5
end
print(x) -- nil
You’ll get nil since x is defined in the block.
Further examples:
local x do
x = 5
print(x) -- 5
end
print(x) -- 5
for i = 1, 5 do
local x = i
end
print(x) -- nil
while example do -- assume example is defined somewhere
local x = 5
end
print(x) -- nil
The main takeaway from this should be that local variables defined within “do end,” regardless of where it’s used, are unable to be used after the “end”