Lovely Professional University: Mittal School of Business
Lovely Professional University: Mittal School of Business
Do – while loop:
do while loop is similar to while loop with the only difference that it checks for the
condition after executing the statements, and therefore is an example of Exit
Control Loop.
Syntax: Syntax
do
{
statements ..
}
while (condition);
Q9: Explain the use of break and continue statement in loops with
example.
1.Functionality
Break statement mainly used to terminate the enclosing loop such as while, do-
while, for or switch statement wherever break is declared.
Continue statement mainly skip the rest of loop wherever continue is declared
and execute the next iteration.
2. Executional flow Break statement resumes the control of the program to the
end of loop and made executional flow outside that loop.
Continue statement resumes the control of the program to the next iteration of
that loop enclosing continue and made executional flow inside the loop again.
3.Usage As mentioned break is used for the termination of enclosing loop.
On other hand continue causes early execution of the next iteration of the
enclosing loop.
4. Compatibility Break statement can be used and compatible with switch ,
label .
We can t use continue statement with switch , lablel as it is not compatible with
them.