| C Tutorial | Break statement | |||
|
If Statement Ternary Operator Switch Statement While Loop Do-While Loop For Loop Break Continue
|
The break statement will move control outside a loop or switch statement. Stylistically speaking, break has the potential to be a bit vulgar. It's preferable to use a straight while with a single test at the top if possible. Sometimes you are forced to use a break because the test can occur only somewhere in the midst of the statements in the loop body. To keep the code readable, be sure to make the break obvious -- forgetting to account for the action of a break is a traditional source of bugs in loop behavior.
while (<expression>) { <statement> <statement>
if (<condition which can only be evaluated here>) break;
<statement> <statement> } // control jumps down here on the break The break does not work with if. It only works in loops and switches. Thinking that a break refers to an if when it really refers to the enclosing while has created some high quality bugs. When using a break, it's nice to write the enclosing loop to iterate in the most straightforward, obvious, normal way, and then use the break to explicitly catch the exceptional, weird cases.
Want To Know more with
Video ???
|
|