Break and Continue Statements
Break Statement
Sometimes it is necessary to stop the loop within its body. Use the break
statement within loops to pass control to the first statement following the innermost switch
, for
, while
, or do
block.
Break
is commonly used in the switch
statements to stop its execution upon the first positive match. For example:
switch (state) { case 0: Lo(); break; case 1: Mid(); break; case 2: Hi(); break; default: Message("Invalid state!"); }
Continue Statement
The continue
statement within loops is used to “skip the cycle”. It passes control to the end of the innermost enclosing end brace belonging to a looping construct. At that point the loop continuation condition is re-evaluated. This means that continue
demands the next iteration if the loop continuation condition is true.
Specifically, the continue
statement within the loop will jump to the marked position as it is shown below:
while (..) { ... if (val>0) continue; ... // continue jumps here }
do { ... if (val>0) continue; ... // continue jumps here while (..);
for (..;..;..) { ... if (val>0) continue; ... // continue jumps here }
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!