File r37/lisp/csl/html/r37_0058.html artifact 2f8767fdae part of check-in d9e362f11e



<A NAME=RETURN>

<TITLE>RETURN</TITLE></A>
<b><a href=r37_idx.html>INDEX</a></b><p><p>



<B>RETURN</B> _ _ _  _ _ _  _ _ _  _ _ _ <B>command</B><P>
<P>
 
The <em>return</em> command causes a value to be returned from inside a 
<em>begin</em>...<em>end</em> 
<A HREF=r37_0041.html>block</A>. 
<P>
<P>
 <P> <H3> 
syntax: </H3>
<em>begin</em>&lt;statements&gt; <em>return</em> &lt;(expression)&gt; 
 <em>end</em><P>
<P>
<P>
<P>
&lt;statements&gt; can be any valid REDUCE statements. The value of 
&lt;expression&gt; is returned. 
<P>
<P>
 <P> <H3> 
examples: </H3>
<P><PRE><TT>
begin write &quot;yes&quot;; 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

</TT></PRE><P>Note in <em>dumb2</em> above that the assignments were made as req
uested, but 
the product <em>c*d</em> cannot be accessed. Changing the procedure to read 
<em>return c*d</em> would remedy this problem. 
<P>
<P>
The <em>return</em> statement is always the last statement executed before 
leaving the block. If <em>return</em> has no argument, the block is exited but 
no value is returned. A block statement does not need a <em>return</em> ; 
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. 
<P>
<P>
The <em>return</em> command can be used inside <em>&lt;&lt;</em>...<em>&gt;&gt;
</em> 

<A HREF=r37_0038.html>group</A> statements and 

<A HREF=r37_0052.html>if</A>...<em>then</em>...<em>else</em> commands that 
are inside <em>begin</em>...<em>end</em> 
<A HREF=r37_0041.html>block</A>s. 
It is not valid in these constructions that are not inside 
a <em>begin</em>...<em>end</em> 
 block. It is not valid inside 
<A HREF=r37_0047.html>for</A>, 

<A HREF=r37_0056.html>repeat</A>...<em>until</em> or 
<A HREF=r37_0228.html>while</A>...<em>do</em> 
 loops in any construction. To force early termination from loops, the 
<em>go to</em>(
<A HREF=r37_0050.html>goto</A>) command must be used. 
When you use nested block statements, a 
<em>return</em> from an inner block exits returning a value to the next-outermos
t 
block, rather than all the way to the outside. 
<P>
<P>
<P>


REDUCE Historical
REDUCE Sourceforge Project | Historical SVN Repository | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]