esperor
esperor

Reputation: 41

Does the number of iterations of the 'for' loop change if the second argument changes in one of the iterations?

i've this code here:

for(i = openGates[0]; i < closeGates[0]; i++) {
    if(str[i] == '(') {
        closeGates.removeFirst();
        openGates.removeAt(1);        
    }
}

If brace found, closeGates[0]'s value will change. Will it change the number of iterations?

Upvotes: 2

Views: 431

Answers (2)

esperor
esperor

Reputation: 41

Apparently, no one decided to answer and I want to close this question so: yes, in C++ 'for' loop evaluates its conditions before every iteration thus the number of the iterations might change.

Upvotes: 2

amolgautam
amolgautam

Reputation: 967

Yes, the iteration-expression is executed after every iteration of the loop. Reference for this answer : https://en.cppreference.com/w/cpp/language/for

Upvotes: 2

Related Questions