Posted By:
2 Jul, 2013 6:41 am PDT

Break statement in C++

What do you by break? What is the use of it?
Attachment:None


Using a ‘break’ we can leave the loop even if the condition is not fulfilled. It can be used to end an infinite loop, or to force its end before its natural end.

For eg:

#include<iostream.h>

int main()

{

int n;

cin>>n;

for(int i=n;n>i;i--)

{

cout<<i<<"\t";

if(i==5)

break; ——————————

}     /* Once the break is encountered it immediately goes to  the next line after the loop. */

cout<<"\nEnd of loop"; //  ←——  

}

 

Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud