13 Jan Break Continue statements in C
Repeatedly execute a block of code using the loop control statements. The following are the loop control statements in C Language:
- break statement
- continue statement
break Statement
Use the break statement, if you want to jump out of a loop. The control passes to the first statement after the loop, since the break statement terminates the loop.
The syntax for break statement:
1 2 3 |
break; |
Example
The following is an example showing the usage of the break statement in C language,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <stdio.h> void main () { int i = 5; while( i < 10 ) { printf("i = %d\n", i); i++; if( i > 7) { break; } } } |
The following is the output showing the usage of the break statement in C Language,
continue statement
Use the continue statement, if you want to pass control to the next iteration of the loop. However, it skips any code in between.
The syntax for continue statement in C language,
1 2 3 |
continue; |
The following is an example showing the usage of the continue statement,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h> void main () { int i = 100; do { if( i == 110) { i = i + 1; continue; } printf("%d\n", i); i++; } while( i < 115 ); getch(); } |
The following is the output,
In this lesson, we learned how to work with loops in C Language. We saw the implementation of the while loop, do-while loop, for loop, break statement, and continue statement.
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:
For Videos, Join Our YouTube Channel: Join Now
Read More:
No Comments