While
While[test, body] evaluates test then body repetitively until test fails to give True.
Example: i = 0; While[i < 0, tot += f[i]; i++]. Note that the roles of ; and , are reversed relative to the C programming language.
See also: Do, For, Table.
Examples
Using InstantCalculators
Here are the InstantCalculators for the While function. Enter the parameters for your calculation and click Calculate to see the result.
In[1]:=
Initialize the variable i before evaluating the While False Text Input.
In[2]:=
In[3]:=
Entering Commands Directly
You can paste a template for this command via the Text Input button on the While Function Controller.
The iteration variable, i, must first be initialized.
In[4]:=
The body of While must have an iteration command. The iteration in this example adds 2.
In[5]:=
Clear the variable definition.
In[6]:=
The body of While can take more that just Print commands. Evaluate the cell to see the output.
In[7]:=
Clear the variable definition.
In[8]:=
|