Reputation: 14660
Consider this C++ code
for(int i=0; i<=N; ++i)
{
if(/* Some condition 1 */) {/*Blah Blah*/}
if(/* Some condition 2 */){/*Yadda Yadda*/}
}
Is there any keyword/command so that if condition 1 evaluates to true
and execution of /*Blah Blah*/
I can skip the rest of the current iteration and begin a new iteration by incrementing i
.
The closest thing I know to this kind of statement skipping is break
but that terminates the loop entirely.
I guess one could do this by using some flags and if statements, but a simple keyword would be very helpful.
Upvotes: 17
Views: 33009
Reputation: 11098
Using the Continue
statement, stops the current loop and continues to the next, rather than breaking altogether
Upvotes: 0
Reputation: 17451
This case seems better suited for if..else.. than a continue, although continue would work fine.
for(int i=0; i<=N; ++i)
{
if(/* Some condition 1 */)
{/*Blah Blah*/}
else if(/* Some condition 2 */)
{/*Yadda Yadda*/}
}
Upvotes: 5
Reputation: 2359
Use the keyword continue
and it will 'continue' to the next iteration of the loop.
Upvotes: 35