Both Break Statement and Continue Statement are important in all programming languages. Here is the definition of both statements with examples...
Break Statement
The break statement is used to exit from a while, for, do, or switch structure. It can be only used inside the body of a for, while, do statement. This statement is used to terminate the control from the switch case as well in the loop. When the break statement is encountered it terminates the execution of the entire loop or switch case. It doesn't bypass the current loop through it transfers the control out of the loop.
Example:
for (i = 1; i<=5; i++)
{
if(i==4)
break;
Printf ("%d", i);
}
Continue Statement
The continue statement is used to bypass the execution of the further statements. When the continued statement is encountered it bypasses a single pass of the loop. It is used to bypass the current pass through a loop. The loop doesn't terminate when continue encountered.
Example:
for (i=1; i<=5; i++)
{
if (i==3)
continue;
Printf("%d", i);
}
The break statement terminates the loop if it meets the condition.
Continue Statement skips the remaining statement.
PREVIOUS POST: What is the time and piece rate system?
Comments
Post a Comment