MathGroup Archive 2000

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

Search the Archive

Building a Table with initially unknown length?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24248] Building a Table with initially unknown length?
  • From: AES <siegman at stanford.edu>
  • Date: Mon, 3 Jul 2000 20:39:28 -0400 (EDT)
  • Organization: Stanford University
  • Sender: owner-wri-mathgroup at wolfram.com

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.)


  • Prev by Date: HELP: personal package
  • Next by Date: Drawing polytopes
  • Previous by thread: Re: HELP: personal package
  • Next by thread: RE: Building a Table with initially unknown length?