I have programmed in C++ earlier but I am new to Python. I searched for this but i was not able to find the appropriate answer. In C++, I can do:
for(int i=0; i<10;i++)
{
i+=5;
std::cout<<i<<std::endl
}
The values of i would be 5 and 11. But in python if i do:
for i in range(0,10):
i+=5
print i
The value of i does update for that iteration of loop, but in the next iteration, it will become 1. While I do understand that in python, after each iteration, i will contain the next value in the tuple/list generated by range, but is there any way I can make it skip iterations like in C++? I really don`t want to use the next() function 5 times
EDIT: I can use the third parameter of range function for general use, but what if I want to skip some iterations for say if only a certain condition is true. eg
for(int i=0; i<10;i++)
{
if(i%2)i+=1;
std::cout<<i<<std::endl
}
rangethird parameter which specify the step size. If that doesn't suit you, consider a regularwhileloop.