RETURN INDEX

RETURN _ _ _ _ _ _ _ _ _ _ _ _ command

The return command causes a value to be returned from inside a begin...end block.

syntax:

begin<statements> return <(expression)> end

<statements> can be any valid REDUCE statements. The value of <expression> is returned.

examples:


begin write "yes"; return a end; 

  yes
  A


procedure dumb(a);
  begin if numberp(a) then return a else return 10 end;

						 

  DUMB 


dumb(x); 

  10 


dumb(-5); 

  -5  


procedure dumb2(a);
  begin c := a**2 + 2*a + 1; d := 17; c*d; return end;
		 

  DUMB2 


dumb2(4); 

c; 

  25 


d; 

  17

Note in dumb2 above that the assignments were made as req uested, but the product c*d cannot be accessed. Changing the procedure to read return c*d would remedy this problem.

The return statement is always the last statement executed before leaving the block. If return has no argument, the block is exited but no value is returned. A block statement does not need a return ; the statements inside terminate in their normal fashion without one. In that case no value is returned, although the specified actions inside the block take place.

The return command can be used inside <<...>> group statements and if...then...else commands that are inside begin...end blocks. It is not valid in these constructions that are not inside a begin...end block. It is not valid inside for, repeat...until or while...do loops in any construction. To force early termination from loops, the go to( goto) command must be used. When you use nested block statements, a return from an inner block exits returning a value to the next-outermos t block, rather than all the way to the outside.