Why doesn’t this python code run infinite times? [closed]

You are confusing c/c++/c# for syntax with python.

In c/c++/c# you have a conditional inside the for syntax:

for (var i= 0; i<100;i++) # this is checked each time you come back here, incrementing
                          # the i will skip some runs and change how often the for is done 

Pythons for is more a foreach:

for i in range(3):

==>

foreach(var k in new []{0,1,2}) # it takes a fresh "k" out every time it comes here
{ ... }

if you modify k it will still only run 3 times.

Leave a Comment