Re: Building a Table with initially unknown length?
- To: mathgroup at smc.vnet.net
- Subject: [mg24243] Re: Building a Table with initially unknown length?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 4 Jul 2000 15:22:07 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <8jrd5i$e2p@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, NestWhile[] ? "NestWhile[f, expr, test] starts with expr, then repeatedly applies f until \ applying test to the result no longer yields True. NestWhile[f, expr, test, \ m] supplies the most recent m results as arguments for test at each step. \ NestWhile[f, expr, test, All] supplies all results so far as arguments for \ test at each step. NestWhile[f, expr, test, m, max] applies f at most max \ times. NestWhile[f, expr, test, m, max, n] applies f an extra n times. \ NestWhile[f, expr, test, m, max, -n] returns the result found when f had been \ applied n fewer times." Regards Jens AES wrote: > > Is there a clean and transparent way to build a Table which grows in > length either to some initially specified maximum length, or until a > test is met? > > One way to do this is obviously to use a While[ ] loop, adding an > element to the table each time around the loop -- but I've been led to > believe that Append'ing an elements to a list is a slower process. > > A related question would be: Is it legal to redefine the upper limit of > the iterator in a Do[ ] or Table[ ] operation? For example would > something like > > kMax=100; > Do[ {k, f1=f[k]; If[ f[1<0, kMax=k+1]; f1}, {k,1,kMax}]; > > build a Table of k and f[k] with up to 100 elements or until f[k] went > negative, whichever came first. (Trial and error says no.)