Re: How to use only part of mapping
- To: mathgroup at smc.vnet.net
- Subject: [mg57298] Re: [mg57257] How to use only part of mapping
- From: János <janos.lobb at yale.edu>
- Date: Tue, 24 May 2005 05:12:35 -0400 (EDT)
- References: <200505220414.AAA17638@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On May 22, 2005, at 12:14 AM, Guy Israeli wrote:
> Hi,
>
> I want to do some mapping (/@) related operations since I don't
> want to use
> for/while loops because of all the index mayhem.
>
> The problem is that I don't need the map operation to continue once
> some
> condition is met.
>
> Is there a way to stop the mapping operation so it will not
> continue, thus
> saving valuable calculation time (since there is no need to continue).
>
> for example (not useful though)
>
> Print[#]&/@Range[10]
> and stop printing if #>5
>
>
> If it isn't possible to do it with map, what are my other options?
>
> Thanks,
>
> Guy
>
>
In[11]:=
Catch[Scan[If[#1 > 5,
Throw[#1], Print[
#1]] & , Range[10]]];
From In[11]:=
1
From In[11]:=
2
From In[11]:=
3
From In[11]:=
4
From In[11]:=
5
János
- References:
- How to use only part of mapping
- From: Guy Israeli <guyi1@netvision.net.il>
- How to use only part of mapping