MathGroup Archive 2003

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

Search the Archive

simple question if/while loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40105] simple question if/while loop
  • From: s kp <kpsj2002 at yahoo.com>
  • Date: Thu, 20 Mar 2003 03:35:00 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I am trying to do the following for a test purpose so I am a learning mathematica

TestFun[] := Module[{a, tb, n},
    tb = Table[0.0, {4}];
    n := 1;
    a := Random[];
    While[n < 5,
        If[ a > .5,
          (tb[[n]] = a;
            n++;), Continue[]
          ]
        ]
      tb
    ]

The output that I get is

{0.871577 Null, 0.512558 Null, 0.00441806 Null, 0.520545 Null}

Why am I doing wrong here and what is the correct way to do the above thing using If and While loop?

thanks

 


  • Prev by Date: Remote site, terminal emulator in Windows
  • Next by Date: Re: Plot3d question
  • Previous by thread: Remote site, terminal emulator in Windows
  • Next by thread: Re: simple question if/while loop