answersLogoWhite

0

The break statement will immediately jump to the end of the current block of code.

The continue statement will skip the rest of the code in the current loop block and will return to the evaluation part of the loop. In a do or while loop, the condition will be tested and the loop will keep executing or exit as necessary. In a for loop, the counting expression (rightmost part of the for loop declaration) will be evaluated and then the condition will be tested.

Example:

#include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf("Hello %d\n", i ); } } #include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf("Hello %d\n", i ); } } #include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf("Hello %d\n", i ); } }

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

if(i == 0) continue;

DoSomeThingWith(i);

}

will not execute DoSomeThingWith for i = 0, but the loop will continue and DoSomeThingWith will be executed for i = 1 to i = 9.

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
More answers

BREAK keyword,

IN Java Break statement has three uses.

First, you use it with SWITCH to terminate the CASE statement.

Second, it can be used to exit the loop.

Third, it can be used as a "goto" statement using label in java.

To handle infinite loop situation and want to exit from deeply nested set of loops break is used.

CONTINUE keyword,

IN Java Continue differs from break.

Continue may required one or more break statement from where to start the code.

Continue provide the structural way to intermediate any statement + loop iteration within program.

In while and do..while loops, a Continue statement causes control to be transferred directly to the conditional expression that controls the loop.But in for loop, control goes first to the iteration portion of the for statement and then to the conditional expression.

User Avatar

Wiki User

11y ago
User Avatar

goto is used to move current program execution to another place specified after goto. break is usually used in loop (for, while, do while) to end the loop or switch statement to prevent the "fall through".

User Avatar

Wiki User

15y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between break and goto in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp