Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Procedural Programming >
Looping Constructs
Looping is a core concept in programming. Mathematica provides powerful primitives for specifying and controlling looping, not only in traditional procedural programming, but also in other, more modern and streamlined programming paradigms.
Do evaluate an expression looping over a variable: Do[expr, {i, n}]
    
While evaluate an expression while a criterion is true: While[crit, expr]
For a "for loop": For[init, test, incr, body]
    
Table build up a table by looping over variables: Table[expr, {i, n}]
    
Nest  ▪ NestWhile  ▪ FixedPoint  ▪ Fold  ▪ ...
    
Scan  ▪ Map(/@)  ▪ MapIndexed  ▪ ReplaceRepeated(//.)  ▪ ...
    
Loop Termination
Throw exit any loop, going to the nearest enclosing Catch
Break  ▪ Continue  ▪ Return  ▪ Interrupt  ▪ Abort
TUTORIALS
MORE ABOUT
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team