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;
#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;
}
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.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.