Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Where does Return return to?

  • To: mathgroup at
  • Subject: [mg48629] Re: Where does Return return to?
  • From: koopman at (Ray Koopman)
  • Date: Tue, 8 Jun 2004 00:48:27 -0400 (EDT)
  • References: <ca1d48$d0r$>
  • Sender: owner-wri-mathgroup at

This may make the problem clearer. 
Why does Return exit Block in func1 but not in func2 or func3? 

In[1]:= func1 := Block[{L = 2}, 
                 While[L > 1, If[True, Return[1]]; L--]; 0]

In[2]:= func2 := Block[{L = 2}, 
                 While[If[True, Return[1]]; --L > 1]; 0]

In[3]:= func3 := Block[{},
                 Do[If[True, Return[1]], {L,2,2,-1}]; 0]

In[4]:= func1
Out[4]= 1

In[5]:= func2
Out[5]= 0

In[6]:= func3
Out[6]= 0

  • Prev by Date: Combining plots
  • Next by Date: Energy content of a mathematical result.
  • Previous by thread: Re: Where does Return return to?
  • Next by thread: Re: Re: Where does Return return to?