Skip to main content

//Break and Continue Statement

 //Break and Continue Statement


  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a = 10; //variable def

  6. while(a <= 20)
  7. {
  8. if(a==15) //(a==15)when... //block of code to be executed if the condition is True.
  9. {
  10. a++; 
  11. cout<<"in if statement of a is:"<<a<<endl; //"endl" use for linebreak. 
  12. continue;                           //  Continue:-when the loop iterate for the first time the value of i=10, the if statement result will be false, so the else condition 2 is                                    implemented.
  13.                      //loop iterates again now i=15; if condition result will be 'True' and the code stop in between and strat new iterate unitl the end condition met.    
  14.                             //you can also use 'break' //      
  15.                            //Break :- when the loop iterates for first time, the value of i=10, the if statement result will be false, so the else condition is executed. 
  16.                 //loop iterates again now i=15; if condition result will be 'True' and loop breaks.
  17. }

  18. cout<<"the value of a is:"<<a<<endl; //"cout" use for print line.
  19. a++; // a++ for this condition 'a <= 20'. value increase upto 20.


  20. }
  21. return 0;
  22. }


//Execute


//Output

/*

//Output for Break

the value of a is:10

the value of a is:11

the value of a is:12

the value of a is:13

the value of a is:14

in if statement of a is:16


//Output for Continue

the value of a is:10

the value of a is:11

the value of a is:12

the value of a is:13

the value of a is:14

in if statement of a is:16

the value of a is:16

the value of a is:17

the value of a is:18

the value of a is:19

the value of a is:20

*/



                                       //ThE ProFessoR