User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
255
Goto Statement
The goto statement is used for unconditional jump to a local label — for more information on labels, refer to Labeled
Statements. The syntax of the goto statement is:
goto label_identier;
This will transfer control to the location of a local label specied by label_identier. The label_identier 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.
goto is used to break out from any level of nested control structures but it cannot be used to jump into block while
skipping that block’s initializations – for example, jumping into loop’s body, etc.
The use of goto statement is generally discouraged as practically every algorithm can be realized without it, resulting
in legible structured programs. One possible application of the goto statement is breaking out from deeply nested
control structures:
for (...) {
for (...) {
...
if (disaster) goto Error;
...
}
}
.
.
.
Error: /* error handling code */
Return Statement
The return statement is used to exit from the current function back to the calling routine, optionally returning a value.
The syntax is:
return [expression];
This will evaluate expression and return the result. Returned value will be automatically converted to the expected
function type, if needed. The expression is optional; if omitted, the function will return a random value from
memory.
Note: The statement return in functions of the void type cannot have expression – in fact, the return
statement can be omitted altogether if it is the last statement in the function body.