       Re: simple question if/while loop

• To: mathgroup at smc.vnet.net
• Subject: [mg40109] Re: simple question if/while loop
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Fri, 21 Mar 2003 02:36:20 -0500 (EST)
• Organization: Universitaet Leipzig
• References: <b5bk79\$5t4\$1@smc.vnet.net>
• Reply-to: kuska at informatik.uni-leipzig.de
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

you forgott a semicolon

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[]]
]; (* <==== here ! *)
tb
]

Regards
Jens

s kp wrote:
>
> 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: Re: UnitStep
• Next by Date: Re: Finding solutions to differential eqns
• Previous by thread: Re: simple question if/while loop
• Next by thread: Re: simple question if/while loop