In C programming, the break is used in terminating the loop immediately after it is encountered. break statement can be used with conditional if statement. It is also used in switch...case statement.
Syntax:
break;
Example:
//Write a C Program Which use of break statement. #include<stdio.h> #include<conio.h> void main(){ int num, sum=0; int i,n; printf("Note: Enter Zero for break loop!\n"); printf("Enter Number of inputs\n"); scanf("%d",&n); for(i=1;i<=n;++i){ printf("Enter num%d: ",i); scanf("%d",&num); if(num==0) { break; /*this breaks loop if num == 0 */ printf("Loop Breaked\n"); } sum=sum+num; } printf("Total is %d",sum); getch(); }
continue Statement
goto Statement
No comments:
Post a Comment