Repetitive Operations

In using the Wolfram Language, you sometimes need to repeat an operation many times. There are many ways to do this. Often the most natural is in fact to set up a structure such as a list with many elements, and then apply your operation to each of the elements.

Another approach is to use the Wolfram Language function Do, which works much like the iteration constructs in languages such as C and Fortran. Do uses the same Wolfram Language iterator notation as Sum and Product, described in "Sums and Products".

Do[expr,{i,imax}]evaluate expr with i running from 1 to imax
Do[expr,{i,imin,imax,di}]evaluate expr with i running from imin to imax in steps of di
Print[expr]print expr
Table[expr,{i,imax}]make a list of the values of expr with i running from 1 to imax

Implementing repetitive operations.

This prints out the values of the first five factorials:
Click for copyable input
It is often more useful to have a list of results, which you can then manipulate further:
Click for copyable input
If you do not give an iteration variable, the Wolfram Language simply repeats the operation you have specified, without changing anything:
Click for copyable input