From the course: Learning MATLAB
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
While loops - MATLAB Tutorial
From the course: Learning MATLAB
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Writing a program8m 37s
-
(Locked)
If/else statements5m 11s
-
(Locked)
For loops5m 46s
-
(Locked)
While loops3m 51s
-
(Locked)
Create and use a function with one input5m 3s
-
(Locked)
Create and use a function with two inputs4m 55s
-
(Locked)
Challenge: Write your first program2m 31s
-
(Locked)
Solution: Write your first program8m 14s
-
-
-