From the course: Learning MATLAB

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

While loops

While loops

- [Instructor] The while loop executes a statement in a loop for an unspecified number of times as long as the logic expression is true. This means that the statement will be repeated in a loop until the condition is met. Compared to the for loop, the number of repetitions, or as we call them passes, is unknown in a while loop. For example, let's have a variable x that is equal to 2, and this is the initial value of the variable. So, while x is less than 30, let's say, for example, then the statement x will be equal to a mathematical expression. Let's say for example, x will be equal to 2 times x in power of 2 1. So this expression is evaluated, or this mathematical expression is calculated. So once x becomes higher than 30, and we can see this in the flow chart. So again, if x is equal to 2 and then if x is less than 30, then yes, the calculation is performed, so x will be equal to 2 times x squared 1. And then if…

Contents