#question about gotos in luau

1 messages · Page 1 of 1 (latest)

rugged elbow
#

official luau page says that goto complicates the compiler and makes control flow unstructured, but how? doesn't luau use goto/jump instructions internally?

buoyant heronBOT
#

studio** You are now Level 1! **studio

rugged elbow
gaunt steeple
#

scope becomes ambiguous when you try to use goto

#

;compile lua ```lua
function a(x)
x=x+1
::thing::
x=x+1
print(x)
return x
end
function b(y)
local x=y
goto thing
return y
end

local output=b(4) -- what should output be, 4, 5, or 6?``` if i wrote that right

digital tokenBOT
#
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:14: no visible label 'thing' for <goto> at line 10

gaunt steeple
#

it usually doesn't pan out well in practice and makes your code unnecessarily more confusing. write closures better and you won't ever need goto.

#

it's the compilers job to fill in the goto's for you