C ++ how to skip next 2 iterations of a loop i.e. Multiple continuation

Let's say I have the following loop:

vector <string> args;
for (string s : args)
{
    if ( s == "condition" )
        continue; // skips to next iteration
}

      

How can I skip multiple iterations in this case? Is there something like multiple continuation statements?

+3


source to share


2 answers


Consider using a loop for

with an index:



for (size_t i = 0; i < args.size(); i++)
{
    if (args[i] == "condition") {
        i++;
        continue;
    }
}

      

+3


source


You can use an iterator.



auto it_end = --args.end();
for(auto it = args.begin(); it != args.end(); it++){
    if ( *it == "condition" && it != it_end) it++;
}

      

+1


source







All Articles