Presentation is loading. Please wait.

Presentation is loading. Please wait.

break & continue Statements

Similar presentations


Presentation on theme: "break & continue Statements"— Presentation transcript:

1 break & continue Statements
Skip or terminate

2 It is sometimes desirable to skip some statements inside the loop or terminate the loop immediately without checking the test expression. In such cases, break and continue statements are used.

3 break Statement The break statement terminates the loop immediately when it is encountered, Simply comes out of the loop. Immediate statement after the closing brace of the loop will be executed. Syntax of break statement break;

4 Flowchart of break statement

5 How break statement works?

6 continue Statement The continue statement skips some statements inside the loop. Loop will restart when continue is encountered. Syntax of continue Statement continue;

7 Flowchart of continue Statement

8 How continue statement works?

9 Examples include<stdio.h> Void main(){ int i;
         for(i=0;i<=4;i++){          printf("%d“,i);          break;          printf("Label 1");     }     printf("Label 2");   } Output: 0 label 2

10 #include<stdio.h>
Void main(){     int i=5;         do{          printf("%d“,i);          continue;          i++;     }     while(i<=10);      } Output: Infinite loop


Download ppt "break & continue Statements"

Similar presentations


Ads by Google