Sylver
Sylver

Reputation: 8967

How to skip several iterations of a for loop

Is there a clean way to skip several iterations from a from a for loop?

Something like:

for (int i = 0; i< count; i++)
{
   if (condition)
   {
       // skip several iterations of "i"
       continue(5);
   }
}

Upvotes: 0

Views: 197

Answers (2)

Hakan Serce
Hakan Serce

Reputation: 11256

You can use the following

i+= 5;
continue;

Upvotes: 3

Szymon
Szymon

Reputation: 43023

You can change the value of i, that will skip some iterations:

for (int i = 0; i< count; i++)
{
   if (condition)
   {
       i+=5;
       continue;
   }
}

Upvotes: 2

Related Questions