You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The break statement is used to exit to loop irrespective of whether the condition is true or not.
4
+
Whether a break statement is encountered inside the loop, the control is selt outside the loop.
5
+
*/
6
+
//example:
7
+
// #include <stdio.h>
8
+
// int main(){
9
+
// for(int i = 0; i <= 10; i++){
10
+
// if(i == 6){
11
+
// break;
12
+
// }
13
+
// printf("%d\t", i);
14
+
// }
15
+
// printf("The loop is ended!");
16
+
// return 0;
17
+
// }
18
+
/*
19
+
Output:
20
+
0 1 2 3 4 5 The loop is ended!
21
+
22
+
The above example should have printed all numbers from 0 to 20 but it printed upto because we added a break statement when i become 6. so the loop ended when i became 6.
23
+
*/
24
+
25
+
/*
26
+
CONTINUE STATEMENT:
27
+
Continue statement is similar to break statement but instead of exiting the loop, it skips the iteration and jumps to the next iteration.
28
+
*/
29
+
//example:
30
+
#include<stdio.h>
31
+
intmain(){
32
+
for(inti=0; i<15; i++){
33
+
if(i==5){
34
+
continue;
35
+
}
36
+
printf("%d\t", i);
37
+
}
38
+
printf("The loop is ended!");
39
+
return0;
40
+
}
41
+
/*
42
+
Output:
43
+
0 1 2 3 4 6 7 8 9 10 11 12 13 14 The loop is ended!
44
+
*/
45
+
/*
46
+
Note:
47
+
1. Sometimes, the name of the variable might not indecate the behaviour of the program.
0 commit comments