Getting Started | ![]() ![]() |
for
The for
loop repeats a group of statements a fixed, predetermined number of times. A matching end
delineates the statements.
for n = 3:32 r(n) = rank(magic(n)); end r
The semicolon terminating the inner statement suppresses repeated printing, and the r
after the loop displays the final result.
It is a good idea to indent the loops for readability, especially when they are nested.
for i = 1:m for j = 1:n H(i,j) = 1/(i+j); end end
![]() | switch and case | while | ![]() |