I have a larger program which uses a lot of while loops, and I have come across 2 ways in how to use them. Both produce the same result, but I am wondering which one is perhaps more efficient in terms of using resources etc.
def loop_1():
var = 0
while var != 1: # Until 'var' is 1
var = int(input("> "))
def loop_2():
while True: # Until 'break' is used
var = int(input("> "))
if var == 1:
break
Both loops stop if you enter 1, but does the break syntax use more memory and resources than a regular while loop in loop_1()? I have a big program with a lot of while loops which all use the break syntax.
while x:orwhile True: ... if ! x: breakShould not make much of a difference in terms of performance. The problem probably lies elsewhere.