This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

For

For
executes start, then repeatedly evaluates body and incr until test fails to give True.
  • For evaluates its arguments in a nonstandard way.
  • For does the loop with a null body.
  • The sequence of evaluation is test, body, incr. For exits as soon as test fails.
  • If Break is generated in the evaluation of body, the For loop exits.
  • Continue exits the evaluation of body, and continues the loop by evaluating incr.
  • Unless an explicit Return is used, the value returned by For is Null.
  • Note that in an example like For the roles of the semicolon and comma are reversed relative to C-like programming languages.
A comma delimits the parts of For; a semicolon delimits the parts of procedures:
 
A comma delimits the parts of For; a semicolon delimits the parts of procedures:
Break breaks out of For:
Continue continues the loop without executing the rest of the body:
A Do loop can be written as a For loop:
New in 1