0

I am having a doubt that like other programming languages we can increment in for loop as we want (eg in c for(i=0; i<5;i+5)) but if we want to do his in python we cant ??????

  • `range` can get a step. Also, your loop would run indefinitely because you wrote `i+5`, not `i=i+5` nor `i+=5`. – h4z3 Jul 22 '19 at 14:00
  • Duplicate of https://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks – Frieder Jul 22 '19 at 14:02
  • Possible duplicate of [To write a java for loop in python](https://stackoverflow.com/questions/52906665/to-write-a-java-for-loop-in-python) – Dmytro Chasovskyi Jul 22 '19 at 14:29
  • Possible duplicate of [What is the most "pythonic" way to iterate over a list in chunks?](https://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks) – Valentino Jul 22 '19 at 14:39

2 Answers2

1

You would do it this way: for i in range(0,5,5):

Moshee
  • 544
  • 1
  • 3
  • 16
0

You can specify strides to do what you want:

for i in range(0, 5, 5):
    print(i)
Carsten
  • 2,765
  • 1
  • 13
  • 28