MathGroup Archive 2006

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

Search the Archive

Strange problem with "for" and "while"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68359] Strange problem with "for" and "while"
  • From: "LordBeotian" <pokipsy76 at ANTISPAMyahoo.it>
  • Date: Wed, 2 Aug 2006 05:24:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

When I try to compute this:

For[k = 1, k < 10, k++,
    i := 0;
    While [k > 1, i++; k--];
    Print[i, k]]

Mathematica outputs a neverending sequence of "1,1" (and it is impossible to 
abort the computation!)

When instead I try to manually do the "for" and compute

k := ...;
i = 0;
While [k > 1, i++; k--];
Print[i, k]

giving to k all the values 1,2,...,9 the computation are all correct (the 
outputs are "01", "11", "21", ..., "81".

I cannot understand what is the problem.


  • Prev by Date: MeanTest Function not Working
  • Next by Date: find area bounded by three linear functions
  • Previous by thread: Re: MeanTest Function not Working
  • Next by thread: Re: Strange problem with "for" and "while"