Home > database >  How to skip the while loop once in Python?
How to skip the while loop once in Python?

Time:12-01

I want to skip the while loop only once. How can I do this?

import time
i = 0
while True:
    
    if i == 3:
        pass
    
    i  = 1
    print(i)
    time.sleep(1)

Thank you.

CodePudding user response:

You can use the continue statement to move to the beginning of the loop and that way "skip" it, but you will need to increment i first.

CodePudding user response:

You can do it like this :-

import time 
i = 0 
while True: 
    i  = 1
    if i == 3: 
        continue   
    print(i) 
    time.sleep(1)
  • Related