Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

simple question if/while loop

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

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[]

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?



  • 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