Jump statements, Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual
Page 130

Jump Statements
A jump statement, when executed, transfers control unconditionally. There are four
such statements in mikroC:
break
,
continue
,
goto
, and
return
.
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 inner-
most
switch
,
for
,
while
, or
do
block.
Break
is commonly used in
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
You can use the
continue
statement within loops (
while
,
do
,
for
) 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-evaluat-
ed. This means that continue demands the next iteration if loop continuation con-
dition is true.
Goto Statement
Use the
goto
statement to unconditionally jump to a local label — for more infor-
mation on labels, refer to Labeled Statements. Syntax of
goto
statement is:
goto
label_identifier
;
This will transfer control to the location of a local label specified by
label_identifier
. The
label_identifier
has to be a name of the label
within the same function in which the
goto
statement is. The
goto
line can come
before or after the label.
mikroC - C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
122
MikroElektronika: Development tools - Books - Compilers
page