Search⌘ K

'goto', but Why?

Explore the history of the 'goto' concept in Python, including an April Fool's joke implementation. Learn why Python avoids this control flow statement to promote clearer, more maintainable code.

We'll cover the following...

Where are we going?

⚠️ The following code is meant for Python 2.3.

Python
from goto import goto, label
for i in range(9):
for j in range(9):
for k in range(9):
print("I am trapped, please rescue!")
if k == 2:
goto .breakout # breaking out from a deeply nested loop
label .breakout
print("Freedom!")

Output

I
...