MathGroup Archive 2006

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

Search the Archive

Strange problem with "for" and "while"


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"