The while statement is used as a conditional loop in MATLAB; it is used to repeat an action whenever ahead of the time it is not known how many times the action will be repeated. The common form of the while statement is as shown below:
The action that consists of any number of statements is executed as long as the condition is true. The condition should eventually become false to avoid an infinite loop. (If this occurs, Ctrl-C will exit the loop.)
The way it works is that, at first the condition is computed. If it is logically true, the action is executed. Therefore, to start with it is merely like an if statement. Though, at that point the condition is computed again. If it is still true, the action is executed once again. Then, the action is computed again. If it is still true, the action is executed again. Then, the action is... ultimately, this has to stop! Ultimately something in the action has to change something in the condition so it becomes false.