answersLogoWhite

0

ANSWER

Continue is used to jump to the end of an iteration in a loop. It is often used in an if statement within a while or for loop to skip the remainder of the loop code.

Example (note: not the easiest way to write this code):

for ( i=0; i<10; i++ )

{

if ( array[i] <= 0 )

{

continue; // do not add this value to the total

}

total += array[i];

}

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
More answers

The continue is another jump statement like the break statement as both the statements skip over a part of code . But continue statement is somewhat different from break.Instead of forcing termination,it forces the next iteration of loop to take place, skipping any code in between.A continue statement will just abandon the current iteration and let the loop start the next iteration.

User Avatar

Wiki User

12y ago
User Avatar

We use the continue keyword within a loop statement (for, while and do) whenever we wish to start a new iteration of the loop, bypassing any and all remaining statements within the loop.

Use of continue should always be conditional, otherwise none of the remaining statements would ever execute.

There are often alternatives to using continue within a loop, but if the condition can be expressed or processed more efficiently with continue then it makes sense to use it.

The following example demonstrates both unconditional and conditional use of continue within while loops. The final loop demonstrates a possible alternative to using continue.

int x = 10;

while( x-- )

{

continue; // Unconditional.

std::cout << x << std::endl; // Never executes!

}

x = 10;

while( x-- )

{

if( x % 2 )

continue; // Conditional.

std::cout << x << std::endl; // Executes when x is even.

}

x = 10;

while( x-- )

{

if( !(x % 2 )) // Alternative to using continue.

std::cout << x << std::endl; // Executes when x is even.

}

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is work of continue statement in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp