Home | | Computer Science 11th std | C++ break statement

Chapter: 11th Computer Science : Chapter 10 : Flow of Control

C++ break statement

A break statement is a jump statement which terminates the execution of loop and the control is transferred to resume normal execution after the body of the loop.

break statement

 

A break statement is a jump statement which terminates the execution of loop and the control is transferred to resume normal execution after the body of the loop. The following Figure. shows the working of break statement with looping statements;


 

Illustration 10.19 C++ program to count N numbers using break statement

#include <iostream>

Using namespace std;

int main ()

{

int count = 0;

do

{

cout<< "Count : " << count <<endl;

count++;

if( count > 5)

{

      break;

}

}while( count < 20 );

return 0;

}

Output

Count : 0

Count : 1

Count : 2

Count : 3

Count : 4

Count : 5

In the above example, while condition specified the loop will iterate 20 times but, as soon as the count reaches 5, the loop is terminated, because of the break statement.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
11th Computer Science : Chapter 10 : Flow of Control : C++ break statement |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.