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 instance? Is there something like multiple continue statements?
Consider using for
loop with index:
for (size_t i = 0; i < args.size(); i++)
{
if (args[i] == "condition") {
i++;
continue;
}
}
You can use iterator.
auto it_end = --args.end();
for(auto it = args.begin(); it != args.end(); it++){
if ( *it == "condition" && it != it_end) it++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With