MathGroup Archive 2011

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

Search the Archive

Re: While Loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123632] Re: While Loop
  • From: João Paulo Pereira <joaopereira9 at gmail.com>
  • Date: Tue, 13 Dec 2011 05:44:43 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jbvjus$j47$1@smc.vnet.net>

Thanks everybody

It is clear now how this works

Joao




On 12/12/11, DrMajorBob <btreat1 at austin.rr.com> wrote:
> Nice.
>
> Bobby
>
> On Sun, 11 Dec 2011 02:49:44 -0600, Oleksandr Rasputinov
> <oleksandr_rasputinov at hmamail.com> wrote:
>
>> On Sat, 10 Dec 2011 12:39:56 -0000, 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.
>>
>> For the syntactical form you give above, test (not "the test", but "the
>> expression called test") is always evaluated before body (ditto). This is
>> standard in Mathematica in that function arguments normally evaluate from
>> right to left. However, what the documentation is saying is that there
>> are
>> variant forms you can use to have "the test" evaluated after "the body".
>> You can, of course, use
>>
>> While[True, body; If[test, Break[]]]
>>
>> but I think the clearest way is the one which omits body entirely ("the
>> expression called body" is implicitly Null). For example,
>>
>> i = 5; While[Print[--i]; i > 0]
>>
>> which prints
>>
>> 4
>> 3
>> 2
>> 1
>> 0
>>
>> and thus demonstrates that it meets your requirements.
>>
>
>
> --
> DrMajorBob at yahoo.com
>
>



  • Prev by Date: Re: Findminimum too slow for iterative reweighted least squares
  • Next by Date: Re: NMinimize problem: fct minimized uses FindRoot
  • Previous by thread: Re: While Loop
  • Next by thread: Re: While Loop