MathGroup Archive 2013

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

Search the Archive

Table with condition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130233] Table with condition
  • From: Šerých Jakub <Serych at panska.cz>
  • Date: Sun, 24 Mar 2013 23:23:10 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

Dear mathgroup,
I need to start creating list and continue until some condition is not met.  For example to generate list of random numbers until the value is not 5. Yes, it is theoreticaly possible to generate list with sufficient length, and cut it on the right place afterwords, but it is very inefficient way if the computation is much harder than just generation of random numbers.

TakeWhile[Table[RandomInteger[{0, 10}], {15}], # != 5 &]

Using the while cycle is the other way, but I can only print values using that method, but I don't know, how to generate classical list:

r = 0;
While[r != 5, r = RandomInteger[{0, 10}]; Print[r]] 

What is the right solution of such a simple problem?

Thanks in advance for any help

Jakub
 



  • Prev by Date: Arranging graphics objects (disks) in rows
  • Next by Date: Re: Arranging graphics objects (disks) in rows
  • Previous by thread: Re: Arranging graphics objects (disks) in rows
  • Next by thread: Re: Table with condition