When will the ‘break’ and ‘continue’ statements be used in programme? Mention the scenario
and write the programme to demonstrate this.
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
Comments
Leave a comment