Break Statement have two condition
1) When break statement is inside a loop , the loop is immediately terminated and the program go to the next statement after the loop.
2) It used to terminate a case in the switch statement,
Example 1 : Break in loop :
#include <stdio.h> #include <stdlib.h> int main() { int i , a=0 ; for (i=0; i<10 ; i++){ printf("a=%d\n",a); a++; if (a>5){ break; } } }
Output sample :
Example 2 : Break statement in switch case .
#include <stdio.h> #include <stdlib.h> int main() { int i , a=0 ; printf("please enter your quiz score over 5 ? \n"); scanf("%d",&a); switch (a){ case 5 : printf ("Excellent\n"); break; case 4 : printf("Very Good\n"); break; case 3: printf("Good\n"); break; case 2 : printf("Pass\n"); break; default: printf("Sorry you are Failed\n"); } return 0 ; }
0 Comment to "Break Statement "
Post a Comment