Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: How to use only part of mapping

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57267] Re: [mg57257] How to use only part of mapping
  • From: DrBob <drbob at bigfoot.com>
  • Date: Mon, 23 May 2005 02:20:36 -0400 (EDT)
  • References: <200505220414.AAA17638@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

For instance:

Catch@Scan[If[#>5,Throw["Done"],Print@#]&,Range@10]

1
2
3
4
5
Done

Scan could be replaced by Map, or another looping structure.

This is more natural, however, despite the indexing:

i = 1
While[i < 5, Print@i; i++];
"Done"

1
2
3
4
5
Done

Bobby

On Sun, 22 May 2005 00:14:25 -0400 (EDT), Guy Israeli <guyi1 at netvision.net.il> 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
>
>
>
>
>



-- 
DrBob at bigfoot.com


  • Prev by Date: manipulating powers
  • Next by Date: Re: Help for an integral
  • Previous by thread: How to use only part of mapping
  • Next by thread: Re: How to use only part of mapping