WHILE logical expression (a block of Minitab commands and macro statements) ENDWHILE |
Repeats a block of commands as long as the logical expression is true. The logical expression follows the same rules as in the IF statement.
Suppose we want to find the root of the equation, y = -1 + x + x3. We know this equation has just one real root and that it is between 0 and 1. The following global macro allows us to find, approximately, what the root is.
GMACRO |
We first initialized the two variables, X and Y, to 0 and -1. Each time through the WHILE-loop, Minitab first checks to see that Y is still less than zero. If it is, we increase X by .01 and calculate Y at this new value. Once the condition fails, that is, once Y is no longer less than zero, we exit the loop and go to the first statement after ENDWHILE. Then we print out the answer.
Note |
Instead of modifying a worksheet variable inside a WHILE / ENDWHILE loop, it may be faster to copy the worksheet variable to a local macro variable, modify the macro variable in the loop, then copy the macro variable back to the worksheet variable. |