Ask Your Question

Revision history [back]

Here are two example functions illustrating breaking out of while and for loops:

def f():
    index = 0
    while True:
        print index
        index += 1
        if index >= 4:
            break

def g():
    for i in range(10):
        if i >= 5:
            continue
        print i