PRODUCTS
Products Overview
Mathematica
Mathematica for Students
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
SUPPORT
Support Overview
Knowledge Base
Learning Center
Community & Forums
Training & Free Seminars
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News & Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Core Language
>
Procedural Programming
>
Looping Constructs
>
Do
>
BUILT-IN MATHEMATICA SYMBOL
Repetitive Operations
Loops and Control Structures
Tutorials »
|
For
While
Table
Nest
NestWhile
Fold
See Also »
|
Language Overview
Looping Constructs
Procedural Programming
New in 6.0: Core Language
More About »
Do
Do
evaluates
expr
times.
Do
evaluates
expr
with the variable
i
successively taking on the values
through
(in steps of
).
Do
starts with
.
Do
uses steps
di
.
Do
uses the successive values
,
, ....
Do
evaluates
expr
looping over different values of
j
, etc. for each
i
.
MORE INFORMATION
Do
uses the standard
Mathematica
iteration specification.
You can use
Return
,
Break
,
Continue
, and
Throw
inside
Do
.
Unless an explicit
Return
is used, the value returned by
Do
is
Null
.
Do
first evaluates
spec
, then localizes the variable specified and successively assigns values to it, each time evaluating
expr
.
Do
effectively uses
Block
to localize values or variables.
In
Do
is effectively equivalent to
Do
.
EXAMPLES
CLOSE ALL
Basic Examples
(2)
Print the first four squares:
n
goes from
to
in steps of
:
Print the first four squares:
In[1]:=
n
goes from
to
in steps of
:
In[1]:=
Scope
(7)
Evaluate
Print
twice:
The step can be negative:
The values can be symbolic:
Loop over
i
and
j
, with
j
running up to
i
-1
:
The body can be a procedure:
Break
breaks out of
Do
:
Continue
continues the loop, without executing the rest of the body:
Generalizations & Extensions
(1)
Give a list of values to iterate over:
Applications
(5)
Generate a symbolic continued fraction:
Build up a list of primes:
Alternatively use
Reap
and
Sow
:
Implement backsubstitution:
Implement LU triangular decomposition of matrices:
The selection sort algorithm:
Properties & Relations
(1)
Equivalent loops:
SEE ALSO
For
While
Table
Nest
NestWhile
Fold
TUTORIALS
Repetitive Operations
Loops and Control Structures
MORE ABOUT
Language Overview
Looping Constructs
Procedural Programming
New in 6.0: Core Language
RELATED LINKS
NKS|Online
(
A New Kind of Science
)
New in 1 | Last modified in 6