Lesson 10 of 55
8 mins readPython Goto & Labels (::label::)
In Plain English
Lua 5.2+ includes structured `goto label` and `::label::` statements for state machines, complex parser jump tables, and emulating loop continues.
Deep Dive: How It Works
Label Syntax: `::label_name::` defines a jump target.
Goto Syntax: `goto label_name` jumps directly to the matching label.
Scoping Rules: Cannot jump into the scope of a new local variable.
Core Rules to Remember

Structured Jumps: Useful for skipping iterations or implementing state machines.

Double Colons (::): Wrap label names in `::name::`.
Live Interactive Example
Hit Run Code to see it liveUsing goto to Emulate Continue in Loops
Python 3.12
1
2
3
4
5
6
7
Output Console
Click "Run Code" to view the rendered output.
How it works: goto continue skipped the print statement when i was even.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Skip Value with goto
Loop `for i = 1, 4 do`. If `i == 2`, `goto skip`.
Print `"Step: " .. i`. Place `::skip::` before `end`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.