Skip to main content
Logo image

Section 2.5 Looping Structures

In the previous section, if-statements allowed your code to choose between different paths based on true/false conditions. Now we shift to a different kind of flow control: repetition. Loops let you repeat blocks of code multiple times, either for a fixed number of iterations or until a condition changes.
MATLAB provides two primary looping structures:
for-loops
Repeat a fixed number of times or once for each value in a list.
while-loops
Repeat as long as a condition remains true.