Answer to Question #295907 in C++ for Harsh

Question #295907

When will the ‘break’ and ‘continue’ statements be used in programme? Mention the scenario


and write the programme to demonstrate this.

1
Expert's answer
2022-02-10T15:15:02-0500

Use `break` to interrupt the loop. Use `continue` to go to the next loop iteration without proccessing rest of the loop's body.

int limit = 3;
int i = 0;
for (; i < 10; i++) {
	if (i == limit) break;
}
// i == 3
int k = 0;
for (i = 0; i < 10; i++) {
    if (i < limit) continue;
    k++; 
}
// k == 7

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog