Home > Enterprise >  i need this continue to skip the entire while loop but it skips just the if loop (i think)
i need this continue to skip the entire while loop but it skips just the if loop (i think)

Time:09-17

while continue_bool:

     try:
            name = input("Name (str): ")
            if (name in used_names):
                print("This name is already in use")
                continue
            quantity = int(input("quantity (int): "))

here is the code. i tested the continue statement and it does what i want it to do in a simple for loop. it seems here the if (x in y) creates a loop of its own that the continue just restarts. how do i make the continue restart the while loop?

CodePudding user response:

Try taking the continue keyword outside the if block

CodePudding user response:

Use break instead of continue

also, if statement doesn't work like a loop

you can see some examples of while loop here

  • Related