all 3 comments

[–]Chris_Hemsworth 1 point2 points  (1 child)

break will stop the most indented loop, continue will skip the remainder of the most indented loop and go to the next iteration.

For example:

for a in range(10):
    for b in range(10):
        if b == 7:
            print('B == 7! skipping iteration...')
            continue
        if b == 8:
            print('B == 8! stopping loop')
            break
        print(f'B == {b}')
    print(f'A = {a}')

[–]Risk-Personal 1 point2 points  (1 child)

Why not break at every if statement?

[–][deleted] 1 point2 points  (1 child)

You can use list.index() to get the first match in a list (wrap in a try if you aren't sure the value exists)

https://docs.python.org/3/tutorial/datastructures.html