Statements affecting flow control
Till now we have seen different conditional constructs and loop construct such as if...else
, while
, for
, switch
and do
statements. Now,we will study break
, continue
and exit
statements which are used to alter the normal flow of program. A loop performs a set of repetitive tasks until the conditional-expression becomes false, but sometimes it is desirable to skip some action statements inside the loop or terminate the loop immediately without checking the conditional-expression. In such cases, break
and continue
statements are used.
Break usage
The break
statement is used to terminate the innermost while
, do...while
, or for
loop that encloses it. The break
statement is also used to break out of switch
statement. Itis meaningful if used inside a loopor with a switch
statement because, outside the body of a loop or switch
, it has no meaning.All loop constructs have their termination conditional-expression, however sometimes it is possible that you achieve your...