for cal in range(1,2):
first = (cal * 3 1)
if (first % 2) == 0:
first = first / 2
else:
first = (first * 3 1)
for me in range(999999):
if (first % 2) == 0:
first = first / 2
else:
first = (first * 3 1)
if first == 1:
print("verified ✔")
break
this program is made to cheek if a number ends up as one if a math equation happens to it.
but the problem is that at then when I say break it will completely stop. but i want it to only stop the for me in range(999999)
.
CodePudding user response:
The problem is not the break
, since the break
breaks from the inner forloop only.
The problem is the wrong usage of the range()
function singe range(1,2)
returns an iterable iterating over the value 1, hence the outer for is useless in this case since it is only running once with cal = 1
To understand it better you can check it with the following:
for value in range(1,2):
print(value)
You will see that only the value 1 is printed even with no break
statement
CodePudding user response:
just remove the break
, it's already the last if in the loop. If there's something not explained here that you need, maybe you can put pass
there to get it out of the loop. Also me is not used in the loop so this code is very confusing. Not really sure what you are trying to accomplish but I think you don't actually need a loop for it from the details you provided.