MathGroup Archive 2010

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

Search the Archive

Why Return[] does not work?


I wrote a function to check if two lists contain equal members:

Intersects[x_List,
  y_List] := (Do[(Print["Outer step ", xi];
    Do[(Print[xi, yi];
      If[xi == yi, (Print["Returning True"]; Return[True])]), {yi,
      y}]), {xi, x}]; False)

But it returns False for interecting lists:

In[47]:= Intersects[{a, b}, {c, a}]
During evaluation of In[47]:= Outer step a
During evaluation of In[47]:= ac
During evaluation of In[47]:= aa
During evaluation of In[47]:= Returning True
During evaluation of In[47]:= Outer step b
During evaluation of In[47]:= bc
During evaluation of In[47]:= ba
Out[47]= False

Few questions:

1) why does not Return[] interrupt the loops?
2) is there better way to implement intersection check?

Thanks


  • Prev by Date: Re: problems with NMinimize
  • Next by Date: Re: Directing formatted output to different notebooks
  • Previous by thread: Re: how uncouple dynamic objects?
  • Next by thread: Re: Why Return[] does not work?