Break and Continue Statements

Break Statement

Sometimes, you might need to stop the loop from within its body. Use the break statement within loops to pass control to the first statement following the innermost loop (for, while, or do).

For example:

	
Lcd_Out(1, 1, "No card inserted")

' Wait for CF card to be plugged; refresh every second
while true
  if Cf_Detect() = 1 then
    break
  end if
  Delay_ms(1000)
wend

' Now we can work with CF card ...
Lcd_Out(1, 1, "Card detected   ")

Continue Statement

You can use the continue statement within loops to “skip the cycle”:

' continue jumps here
for i = ...
  ...
  continue
  ...
next i
' continue jumps here
while condition
  ...
  continue
  ...
wend
do
  ...
  continue
  ...
' continue jumps here
loop until condition

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code