While
Usage
• While[test, body] 重复计算test然后是body,直到test第一次不能给出True。
Notes
• While[test] 在一个空体中循环。 • 如果在计算body时产生Break[ ],退出While循环。 • Continue[ ] 退出body的计算,继续循环。 • 除非产生Return[ ]或Throw[ ],由While返回的最后结果是Null。 • 例如: i=0; While[i < 0, tot += f[i]; i++]. 注意 ; 和 , 的作用与在 C 程序语言中是相反的. • 参见 Mathematica 全书 : 节 2.5.9.
Further Examples
The While loop continues until the condition fails.
In[1]:=
|




In[2]:=
|
|