shangsunset shangsunset - 10 days ago 7
C++ Question

how to control increments with a variable in python for loop

Here is a for loop in

C++
, how can I achieve the same in with
for
loop in Python? Incrementing
i
by
k+1
?

for (int i = 0; i < some_string.size();) {

int k = i;
while (some_condition) ++k;
i = k+1;
// ....


}

Answer

The following lines of code do the same thing as c++ code in question; however, I don't know if this is the goal you want to achieve:

i = 0
while i < len(some_string):
    k = i
    while some_condition:
        k += 1
    i = k + 1