Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7125

Re: While Loop

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: While Loop
Date 2011-12-11 08:59 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jc1ref$t4p$1@smc.vnet.net> (permalink)
References <201112101230.HAA19372@smc.vnet.net>

Show all headers | View raw


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@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
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: While Loop Bob Hanlon <hanlonr357@gmail.com> - 2011-12-11 08:59 +0000

csiph-web