break — Advanced Playground
Exits the nearest enclosing for or while loop immediately
Python Playground
Output
Click "Run" to execute your codebreak works with any loop, including those over infinite iterators. Combined with walrus operator, it enables clean sentinel-based loops.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?