Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 1979

HOW CAN I RESTART A WHILE LOOP?

by Planet - 04 February, 2021 - 12:11 AM
This post is by a banned member (Planet) - Unhide
Planet  
Heaven
2.539
Posts
829
Threads
4 Years of service
#1
basically I have a loop which structure is:
While True:
code
if var_x == "kek"
continue
else
break
code
if var_y == "cringe"
continue
else
break

is there a way to make the loop restart at the first continue if that condition is met? otherwise it wouldnt reach the code past the 1 break
This post is by a banned member (ANG) - Unhide
This post is by a banned member (ImUndefined) - Unhide
76
Posts
27
Threads
5 Years of service
#3
Something like this would work. Also, you can try asking StackOverflow  kek

def loop():
if var_x == "kek"
c ontinue
else
break
code
if var_y == "cringe"
continue
else
break

def main():
while True:
loop()
This post is by a banned member (ANG) - Unhide
This post is by a banned member (Planet) - Unhide
Planet  
Heaven
2.539
Posts
829
Threads
4 Years of service
#5
me tryna learn python no bully pls ty needed
This post is by a banned member (ume31284) - Unhide
This post is by a banned member (Credits) - Unhide
Credits  
Registered
22
Posts
14
Threads
3 Years of service
#7
def loop():
    while True:
        print('first condition')
        if var_x == "kek":
            loop()
        else:
            break

    while True:
        print('second condition')
        if var_y == "cringe":
            loop()
        else:
            break

    print('outside')

loop()

If the first condition is true, the loop will restart. Else, it will check the next condition and if it is true again, the loop will restart from the beginning.
 

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)