Do
Do[expr,n]
evaluates expr n times.
Do[expr,{i,imax}]
evaluates expr with the variable i successively taking on the values 1 through imax (in steps of 1).
Do[expr,{i,imin,imax}]
starts with i=imin.
Do[expr,{i,imin,imax,di}]
uses steps di.
Do[expr,{i,{i1,i2,…}}]
uses the successive values i1, i2, ….
Do[expr,{i,imin,imax},{j,jmin,jmax},…]
evaluates expr looping over different values of j etc. for each i.
Details
- Do uses the standard Wolfram Language 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[expr,Infinity] continues evaluating expr until explicitly told to exit through a function such as Break, Return, Throw, Abort, or Quit.
- Do[expr,spec] 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.
- Do[expr,spec1,spec2] is effectively equivalent to Do[Do[expr,spec2],spec1].
- Parallelize[Do[expr,iter]] or ParallelDo[expr,iter] computes Do[expr,iter] in parallel on all subkernels. »
Examples
open allclose allBasic Examples (3)
Scope (8)
Generalizations & Extensions (2)
Give a list of values to iterate over:
ParallelDo computes Do in parallel:
Do can be parallelized automatically, effectively using ParallelDo:
Applications (5)
Text
Wolfram Research (1988), Do, Wolfram Language function, https://reference.wolfram.com/language/ref/Do.html (updated 2015).
CMS
Wolfram Language. 1988. "Do." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Do.html.
APA
Wolfram Language. (1988). Do. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Do.html