Break, continue and goto statement in C
Break statement Break statement is used to break the process of a loop (while, do while and for) and switch case.
Syntax: break;Example 1
while(test Expression) { // codes if(condition for break){ break; } // codes }Example 2
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:
continue;Let us take an example:
#include <stdio.h> void main(){ int i; for(i=1;i<=5;i++){ if(i==2) { continue; } printf("%d \n",i); } }Output
1 3 4 5Goto Statement Goto statement is used to transfer the unconditional program control to a labeled statement. Syntax:
Goto identifier;Example:
#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
Hello We are Learning C Language Tutorial Hope you are fine