Do
Usage
• Do[expr, imax ] 对 expr赋值 imax 次.
• Do[expr, i, imax ] 利用变量 i 以步长1递增至 imax 对expr赋值.
• Do[expr, i, imin, imax ]从 i = imin开始. Do[expr, i, imin, imax, di ]使用步长 di.
• Do[expr, i, imin, imax , j, jmin, jmax , ... ] 对每一个 i 循环地根据不同的 j 等对 expr赋值.
Notes
• Do使用标准的 Mathematica迭代规范. • Do以一种非标准的方式对它的参数进行赋值(参见 A.4.2节). • 你可以在Do的内部使用Return, Break, Continue和Throw. • 如果没有使用一个明确的返回, Do的返回值为Null.
Further Examples
Here is a simple Do loop to add the first 1000 integers.
In[1]:=
|
In[2]:=
|
In[3]:=
|
Out[3]=
|
In[4]:=
|
This loop creates a series of graphics that can be animated. Double-click on the graphic to start the animation, or select the cell brackets containing the graphics and choose Animate Selected Graphics in the Cell menu. Evaluate the cell to see the graphic.
In[5]:=
|
|