MathGroup Archive 2011

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

Search the Archive

Re: While Loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123574] Re: While Loop
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sun, 11 Dec 2011 03:49:55 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201112101230.HAA19372@smc.vnet.net>

The test is evaluated first; however, you can achieve the effect of
its being evalated last.

n = 0;

While[n < 3, Print[n]; n++]

0

1

2

n = 0;

While[n < 3, Print[n++]]

0

1

2

n = 0;

While[n < 3, n++; Print[n]]

1

2

3

n = 0;

While[n++ < 3, Print[n]]

1

2

3


Bob Hanlon


On Sat, Dec 10, 2011 at 7:30 AM, Joao <joaopereira9 at gmail.com> wrote:
> Hi, everybody
>
> Could someone help me regarding the While Loop.
>
> While[test,body]
>
> In the help "While" it is stated that the test may be evaluated at the end of the loop, instead of at the beginning. However in the tutorial on Loops and Control structures it is stated that the While always evaluates the test at the beginning.
>
> I would like to know if it is really possible to evaluate the test inside de While at the end of the loop. This is a feature that would be useful for what I'm doing, however I haven't been able to get it working and I don't know, taking into consideration the above, if I am doing something wrong or if it is really not possible to do.
>
> Thanks in advance
>
> Joao
>



  • References:
  • Prev by Date: Re: C/Fortran-like #include functionality for large expressions?
  • Next by Date: Re: LinearProgramming[]
  • Previous by thread: While Loop
  • Next by thread: Re: While Loop