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

• To: mathgroup at smc.vnet.net
• Subject: [mg33753] Re: How to Return from within a Table[]-Command?
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Thu, 11 Apr 2002 02:14:07 -0400 (EDT)
• Organization: Universitaet Leipzig
• References: <a90goo\$kdb\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

a) use a pattern to restrict the argument

Divide2[L:{__Integer}]:=

b) Catch[] and Throw[] are for nonlocal returns

Divide2[L_List] := Catch[
Table[
If[IntegerQ[L[[i]]], i/2, Throw[\$Failed]], {i, 1, Length[L]}]
]

Regards
Jens

Detlef Mueller wrote:
>
> 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: How to specify a parameter
• Next by Date: Re: Simplifying of rules
• Previous by thread: Re: How to Return from within a Table[]-Command?
• Next by thread: RE: How to Return from within a Table[]-Command?