+ 1

for loop counter variable

Hi, Does for loop in python only works with ranges? Is there a way to do a loop with variable control like in c or java or is it only possible using a while loop? Java example for(int i=0;i<X;i++)

1st Jan 2018, 12:34 AM
Benjamin Mendoza
Benjamin Mendoza - avatar
2 Answers
+ 2
for i in range(x): # code will result in basically the same as the for loop you have. You can also loop over a collection such as a list. lst = ['a', 'b', 'c',...] for item in lst: # code
1st Jan 2018, 12:40 AM
ChaoticDawg
ChaoticDawg - avatar
0
Nope, not possible explicitly. for e in range(0, X, 1): is basically the same thing, though you could strip off the third argument of the range function.
1st Jan 2018, 1:09 AM
LunarCoffee
LunarCoffee - avatar