User manual
230
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Exit Statement
The exit statement allows you to break out of a routine (function or procedure). It passes the control to the rst
statement following the routine call.
Here is a simple example:
procedure Proc1();
var error: byte;
begin
... // we’re doing something here
if error = TRUE then exit;
... // some code, which won’t be executed if error is true
end;
Note: If breaking out of a function, return value will be the value of the local variable result at the moment of exit.
Goto Statement
Use the goto statement to unconditionally jump to a local label — for more information, refer to Labels. Syntax of the
goto statement is:
goto label_name;
This will transfer control to the location of a local label specied by label_name. The goto line can come before or
after the label.
The label declaration, marked statement 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.
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 goto statement is breaking out from deeply nested control
structures:
for (...) do
begin
for (...) do
begin
...
if (disaster) then goto Error;
...
end;
end;
.
.
.
Error: // error handling code