The goto system is related to goto in the C language (and many others) and will be familiar to those with experience outside Lua.

How to use GotoEdit

Goto allows the user to define code blocks with Labels and the jump to them or "goto" them, at any point.

A label is defined with two colons (::) on either side of it's name.


To jump to the code directly after that label write:

goto a_label

Be aware that labels will "fall through". In the example below, if at line 3, math.random() !< 0.3, then the ::b:: label will run.

from the lua manual :

  print 'A'
  if math.random() < 0.3 then goto c end
  print 'B'
  if math.random() < 0.5 then goto a end
  print 'C'
  if math.random() < 0.1 then goto a else goto b end

See also Edit

Community content is available under CC-BY-SA unless otherwise noted.