I am learning Python and I came across something with the for
loop.
Let's say I have a program that asks for 5 numbers. (I know it's pointless but it's good for an example.) Anyways, if I do this, it won't restart its cycle:
myNumbers = []
for x in xrange(5):
try:
myNumbers.append( int(raw_input()) )
except ValueError:
myNumbers = []
x = -1
I thought if I had reset x
to -1
it would just make the for
loop go on even more, but it never restarted. It still only went 5 times. The reason why I put -1
there is because x
would count back up to 0
right after that. I tried to find solutions, but there weren't any. Thank you for helping me.