Can anyone tell me what's wrong with this code snippet? How will you improve it?
a = 1
while a:
a += 23
print a
infinite loop.
you should add a condition to break
a = 1
while a:
a += 23
print a
# assuming you do not want it to run forever
if a > 100:
break
It would result in a potential infinite loop.
You are evaluating a as boolean, but treating it as numeric. That's never a good idea.
Jason Knight
The less code you use, the less there is to break
Assuming that's python, the fact that it would take an unknown amount of time to exit since you'd have to wait for a number limit rollover to stumble upon zero for the while statement to finish... You have no planned exit condition unless your intent is LITERALLY to see whatever the max_integer size (assuming integer) does and how many times you can add 23 to one until the rollover zero's... which could be one HELL of a long time.
It's a bit like the US involvement in Afghanistan -- there is no exit strategy.