Break statement
Break statement is used to break the process of a loop (while, do while and for) and switch case.
1 2 3 |
Syntax: break; |
Example 1
1 2 3 4 5 6 7 8 9 10 |
while(test Expression) { // codes if(condition for break){ break; } // codes } |
Example 2
1 2 3 4 5 6 7 8 9 10 |
For(int it, condition, upgrade { // codes if(condition for break){ break; } // codes } |
Continue Statement:
The Continue statement is used to continue the execution of the loop. It is used inside if condition. We can use it with while, do while and for loop.
Syntax:
1 2 3 |
continue; |
Let us take an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <stdio.h> void main(){ int i; for(i=1;i<=5;i++){ if(i==2) { continue; } printf("%d \n",i); } } |
Output
1 2 3 4 5 6 |
1 3 4 5 |
Goto Statement
Goto statement is used to transfer the unconditional program control to a labeled statement.
Syntax:
1 2 3 |
Goto identifier; |
Example:
1 2 3 4 5 6 7 8 9 10 11 |
#include <stdio.h> void main(){ printf("Hello We are Learning C Language Tutorial\n"); goto label; printf("How Are You?"); // skipped printf("Are You Okey?"); // skipped label: printf("Hope you are fine"); } |
Output
1 2 3 4 |
Hello We are Learning C Language Tutorial Hope you are fine |