1

The Do loop is somewhat similar to the Table command, where a definite range is given over which to carry out the commands. The While loop is more of a traditional loop, where a test is performed on each step.

In[1]:=

i = 0 ; n = Input["Give N"] ; a = {} ;

While[i<n, a = Append[a, {i, N[Sin[i]]}] ; i ++] ;

Print[a//TableForm]

0 0.`
1 0.8414709848078965`
2 0.9092974268256817`
3 0.1411200080598672`
4 -0.7568024953079282`
5 -0.9589242746631385`
6 -0.27941549819892586`
7 0.6569865987187891`
8 0.9893582466233818`
9 0.4121184852417566`

In[4]:=

i = 0 ; n = Input["Give N"] ; a = {} ;

Do[a = Append[a, {i, Sin[i]//N}], {i, 0, n, 1}] ;

Print[a//TableForm]

0 0.`
1 0.8414709848078965`
2 0.9092974268256817`
3 0.1411200080598672`
4 -0.7568024953079282`
5 -0.9589242746631385`
6 -0.27941549819892586`
7 0.6569865987187891`
8 0.9893582466233818`
9 0.4121184852417566`
10 -0.5440211108893698`

Created by Mathematica  (April 10, 2007) Valid XHTML 1.1!