Previous

Return Statements

The return statement terminates a subprogram. This statement is required in function definitions and is optional in procedure definitions. The syntax follows.

return expression ;      -- Functions
return ;                 -- Procedures

The required expression provides the function's return value. Every function must have at least one return statement. The expression's type must match the declared function type. A function can have more than one return statement. Only one return statement is reached by a given function call.

A procedure can have one or more return statements, but no expression is allowed. A return statement, if present, is the last statement executed in a procedure.

In the example below, the function OPERATE returns either the AND or the OR of its parameters A and B. The return depends on the value of its parameter OPERATION. The resulting circuit is shown in the figure following the example.

function OPERATE(A, B, OPERATION: BIT) return BIT is
begin
     if (OPERATION = '1') then
          return (A and B);
     else
          return (A or B);
     end if;
end OPERATE;

Figure 6.9 Circuit for Using Multiple return Statements

Next