While loops, MATLAB in Statistics

WHILE Loops:

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:

while condition

action

end

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.

 

 

Posted Date: 10/19/2012 6:02:28 AM | Location : United States







Related Discussions:- While loops, Assignment Help, Ask Question on While loops, Get Answer, Expert's Help, While loops Discussions

Write discussion on While loops
Your posts are moderated
Related Questions
#qYou will need to examine two of the nine sections of data: one section of qualitative data (choose either Gender or Position) one section of quantitative data (choose either Intr

Example of customizing plots: As the other illustration of customizing plots, the pieces of a pie chart can be "exploded" from the rest. In this situation, the two vectors are

Combining Nested FOR Loops and the IF Statements: The statements inside a nested loop can be any of the valid statement, involving any selection statement. For e.g., there can

Editor/Debugger: The MATLAB has numerous useful functions for debugging, and debugging can also be completed through its editor, which is known as the Editor/Debugger. Typi

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

Illustration of Input in a for loop: In this illustration, the loop variable iv iterates through the values 1 through 3, therefore the action is repeated three times. The acti

Nested Functions: We have seen that the loops can be nested, that means that one inside of the other, functions can be nested. The terminology for nested functions is that an

Use of function polyval: The better the curve fit, the more exact these interpolated and extrapolated values will be. By using the subplot function, we can loop to display the

Input in a While Loop: The script below repeats the procedure of prompting a user, the reading in a positive number, and echo-printing it, as long as the user properly enters

Help function: Function is computing the two values, there are two output arguments in the function header (i.e., area & circum), that are placed in the square brackets [ ]. A