list = ['a', 'b', 'c', 'd']
#first option
k=0
for thing in list:
print(thing)
k=k+1
#second option
for thing in list:
print(thing)
The two options below output the same result. Is there a reason to prefer one over the other?
Also, what happens when the value of k becomes 4 in the first option? Is it just somehow hard-coded in Python that when all the elements of a list of length n have been "used up", then the algorithm is forced to stop at step n (i.e., when the counter becomes k=n)?