while Loops
Q. What is a while loop?
A. A while loop is an iteration structure that repeats a set of instructions over and over again as long as a given condition is true. The repetition stops when the given condition is false.
Example application: Coach to team – “Run around this field if you can (are not tired or injured) and keep running till you cannot do so anymore (are tired or injured).”
Users are encouraged to read through the following primer:
While Loops Primer
While Loops Applications
While Loops Advanced Primer
Writing simple while loops | Tutorials | MATLAB programs |
---|---|---|
Write a statement N times | whileloop_writeNtimes.m | |
Write a statement till given condition is satisfied | whileloop_writestatement.m | |
Display numbers from a Start Count to an End Count (specified by the user) | whileloopdisplaycount.m | |
Build a vector | whileloop_buildvector1.m | |
Compute a running sum | runningsum1toTotal.m |