0
Defining a function containing "continue" outside of a loop
I'm attempting to clean up my code and I have a series of repeated functions, so I'm trying to define them once, then insert them into the loop. The problem is each function contains "continue" and I get a syntax error if this is included in the definition. The code works fine once inside the loop, but I can't define it outside of the loop as the "continue" confuses it. def ipt(numx, card): numx = input("Enter " + card + " number: ") if numx in list: int(numx) else: print("That's not an integer from 1-6") continue while True: ipt(num1, "1st") ipt(num2, "2nd") ipt(num3, "3rd") etc.
2 ответов
+ 3
Remove the continue keyword from the function and put it in the loop, make the function return a value, evaluate the returned value and decide whether to continue the loop based on that value.
But srsly, what does the code actually do. What are you trying to achieve and why is it in an infinite loop.