5 return statement, 6 exit statement, Return statement – Rice Lake iRite IDE User Manual

Page 31: Exit statement

Advertising
background image

920i

Programming Reference - Language Syntax

27

To be the best by every measure

3.4.5

Return Statement

The return statement can only be used inside of subprograms (functions, procedures, and event handlers). The
return statement in procedures and handlers cannot return a value. An explicit return statement inside a procedure
or handler is not required since the compiler will insert one if the return statement is missing. If you want to
return from a procedure or handler before the code body is done executing, then you can use the return statement
to exit at that point.

procedure DontDoMuch;

begin

if PromptUser("circle: ") <> SysOK then

return;

end if;

end;

Functions must return a value and an explicit return statement is required. The data type of the expression
returned must be compatible with the return type specified in the function declaration.

function Inc(var viNumber : integer) : integer;

begin

viNumber := viNumber + 1;

return viNumber;

end;

It is permissible to have more than one return statement in a subprogram, but not recommended. In most
instances it is better programming practice to use conditional execution (using the if statement) with one return
statement at the end of the function than it is to use a return statement multiple times. Return statements
liberally dispersed through a subprogram body can result in “dead code” (code that never gets executed) and
hard-to-find bugs.

RETURN

optional-return-value

;

Figure 3-18. Return Statement Syntax

3.4.6

Exit Statement

The exit statement is only allowed in loops. It is used to immediately exit any loop (loop-until, for-loop,
while-loop) it is called from. Sometimes it is convenient to be able to exit from a loop instead of testing at the
top. In the case of nested loops (a loop inside another loop), only the innermost enclosing loop will be exited. See
the loop examples in Section 3.4.4 on page 25 for the exit statement in action.

EXIT

;

Figure 3-19. Exit Statement Syntax

Advertising
This manual is related to the following products: