Nathan Chan Nathan Chan - 9 months ago 37
Python Question

Break out of Loop but Still make Loop Useable

I'm a beginner to Python, so this might sound pretty easy.

Anyway, I'm a little confused on when to use

break
,
pass
, or
continue
. I want to have a loop where it breaks out of it, but then after all the code runs again, then the loop will run again. This is some example code:

score = 100
while True:
score + 1
# break, continue, or pass

score - 30


Basically, what I want to happen is have score go up by 1, then have it go down by 30, and then keep going up by 1.

How can I achieve this? Thanks in advance!

Answer Source
score = 100
first = True
while True:
    while True:
        score += 1
        if first:
            first = False
            break
    score -= 30