Does anyone use the do end blocks?

So I’ve recently learned that in Lua you can do something like this

 -- code here

Does anyone use this and if so, how is it useful?

Actually I have used this type of block once but the way I discovered it was quite funny, I was typing a while loop and by accident my keyboard slipped and the while argument part removed and I noticed there was no Syntax error, I ran the code and there was no yield. But its safe to say I don’t use it much, and when I use it I usually wrap it around a coroutine thread.

Is there a reason for why you do this?

Necessarily as I said it doesn’t yield the code however it runs before the code, so sometimes when I need a code to yield something in the given field while running before it and not yielding the whole code I would use that.

1 Like

Theyre pretty much generally used whenever you want to create a temporary scope to do something without having to do something dumb like:

if true then
    --do stuff

So like if I wanted to do a big calculation without saving the intermediary stuff, I could do something like

local result
    local alpha = a*b*c*d*e*f*g^2
    local beta = math.abs(math.sqrt(50000000)^2*alpha)
    local bread = m*x+b
    local aaaaaaaaaa = (-b+math.sqrt(b^2-4*a*c))/(2*a)
    local bbbbbbbbbb = (-b-math.sqrt(b^2-4*a*c))/(2*a)
    result = alpha+beta/bread*aaaaaaaaaa/bbbbbbbbbb

Normally this could be done in a function or something like that so theyre really not all that necessary, but if you know about them you could find a use for them here and there
But yeah you could really use it however, its just a way to make a scope without any of the extra stuff like functions or if statements

1 Like