C++ Programming Code Examples C++ > For Loops and While Loops Code Examples Break and Continue statement Break and Continue statement We used break statement in switch...case structures. We can also use "break" statement inside loops to terminate a loop and exit it (with a specific condition). In above example loop execution continues until either num>=20 or entered score is negative. while (num<20) { printf("Enter score : "); scanf("%d",&scores[num]); if(scores[num]<0) break; } Continue statement can be used in loops. Like breakcommand continue changes flow of a program. It does not terminate the loop however. It just skips the rest of current iteration of the loop and returns to starting point of the loop. Example 1 (break) #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { printf("value of a: %d\n", a); a++; if( a > 15) { /* terminate the loop using break statement */ break; } } return 0; } value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 Example 2 (continue) #include<stdio.h> main() { while((ch=getchar())!='\n') { if(ch=='.') continue; putchar(ch); } } In above example, program accepts all input but omits the '.' character from it. The text will be echoed as you enter it but the main output will be printed after you press the enter key (which is equal to inserting a "\n" character) is pressed. As we told earlier this is because getchar() function is a buffered input function.