Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to affect the range counter in Python?

Tags:

java

python

I'm trying to run a python program with a for loop which has a variable i increased by 1 every time from 1 to the length of my list. In java, my code that I'm going for might look something like this:

for (int i = 0; i < array.length; i++) {
      //code goes here
      i += //the number i want it to go up by
}

This actually affects my counter the way intended and allows me to effectively skip numbers in my for loop and I want to try to run a similar program but in python. Is there any way to do this with python's built in functionality or do I have to just use a while loop and a counter to simulate this myself if I want python to work this way?

like image 689
JoshKopen Avatar asked Jun 19 '17 18:06

JoshKopen


1 Answers

You'll need a while loop for this:

i = 0
while i < len(myArray):
    # do stuff
    if special_case: i+= 1
    i += 1
like image 146
inspectorG4dget Avatar answered Sep 28 '22 03:09

inspectorG4dget