Here, break is the keyword known to the compiler.
The break statement is used to break from any kind of loop. Let us understand the use of break statement using an example.
Example:
for(i=0;i<10;i++){
/*block of statement*/
}
Let us suppose that we want to come out of for loop when the value of I equals to 5. The solution to this is using break statement. The problem can be solved using break loop as follows:
for(i=0;i<10;i++){
/*block of statement*/
if(i==5)
break;
}
When the break statement is executed the control is transferred to the statement present immediately after the for loop.
No comments:
Post a Comment