Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

RE: How to Return from within a Table[]-Command?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33764] RE: [mg33728] How to Return from within a Table[]-Command?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 11 Apr 2002 02:14:33 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Detlef,

Use Throw and Catch.

Divide2[L_List] :=
   Catch[Module[{newlist},
    newlist =
        Table[
      If[IntegerQ[L[[i]]],
        i/2, 
        Throw["vector not valid."];
        ]
      , {i, 1, Length[L]}
      ];
   newlist
    ]]

Divide2[{2, 3, a}]
"vector not valid."

Divide2[{2, 3, 4.5}]
"vector not valid."

Divide2[{2, 3, 4}]
{1/2, 1, 3/2}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 





> From: Detlef Mueller [mailto:dmueller at mathematik.uni-kassel.de]
To: mathgroup at smc.vnet.net
> 
> 
> Hello,
> 
> I wanted to scan trough al List, building a new
> List, but aborting, if one Element of the first
> List violates a special Condition ... 
> say for example:
> 
> Divide2[L_List] := Module[{},
>     Table[
>       If[IntegerQ[L[[i]]],
>         i/2, 
>         Return["vector not valid."];
>         ]
>       , {i, 1, Length[L]}
>       ]
> 
>     ...
> 
>     ]
> 
> But this results:
> 
> In[13]:= Divide2[{2,3,a}]
> Out[13]= {1/2, 1, Return["vector not valid."]}
> 
> Wich is of course not what I want.
> 
> Greetings
> 
>   Detlef
> 


  • Prev by Date: RE: Interval arithmetic, of a sort
  • Next by Date: Problems with creating packages (formatting)
  • Previous by thread: Re: How to Return from within a Table[]-Command?
  • Next by thread: Re: How to Return from within a Table[]-Command?