User manual
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
233
Label and goto statement must belong to the same block. Hence it is not possible to jump into or out of a procedure
or function.
You can use goto to break out from any level of nested control structures. Never jump into a loop or other structured
statement, since this can have unpredictable effects.
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 i = 0 to n
for j = 0 to m
...
if disaster
goto Error
end if
...
next j
next i
.
.
.
Error: ‘ error handling code
Gosub Statement
Use the gosub statement to unconditionally jump to a local label — for more information, refer to Labels. The syntax
of the gosub statement is:
gosub label_name
...
label_name:
...
return
This will transfer control to the location of a local label specied by label_name. Also, the calling point is remembered.
Upon encountering the return statement, program execution will continue with the next statement (line) after gosub.
The gosub line can come before or after the label.
It is not possible to jump into or out of routine by means of gosub. Never jump into a loop or other structured statement,
since this can have unpredictable effects.
Note: Like with goto, the use of gosub statement is generally discouraged. mikroBasic PRO for dsPIC30/33 and
PIC24 supports gosub only for the sake of backward compatibility. It is better to rely on functions and procedures,
creating legible structured programs.