I am coming from a c++ language and there if i change the value of 'i' in the loop then it affect the iteration of the loop but it is not happening in python.
for example, in c++:
for(int i=0; i<10; i++){
cout<<i<<" ";
if(i==5)
i = 8;
}
in above code, as the value of 'i' reaches 5 it become 8 and after one more iteration it become 9 and then loop ends. output of the above code is-
0 1 2 3 4 5 9
but when i write the similar code in python it doesn't affect the iteration and the loop runs all 10 times.
code in python is -
for i in range(0, 10):
if i == 5:
i = 8
print(i, end=" ")
the output of this code is -
0 1 2 3 4 8 6 7 8 9
it is just changing the value of 5 to 8, and not changing the loop iteration.
how can i achieve the c++ result in python, please help!
thanks in advance :)