How to break out of a loop only if a certain case is executed, but then continue the iteration?

I understand that the name can be somewhat confusing, so I apologize.

Basically, this is my code:

while i < 5:
   do stuff
   if i == 3:
      print "i is 3"
      break

Now it all sounds pretty simple, right? Also, I don’t want BREAK out of the loop as badly as I would like it to start again. So in this case, the desired result would be an iteration through 1, 2, then when 3 breaks out, and then continue repeating from 4. How to do this?

+5
source share
2 answers
while i < 5:
   do stuff
   if i == 3:
      print "i is 3"
      continue
+8
source

breakUse insteadcontinue

, , , , , , . , , , .

+2

All Articles