The syntax of for loop is as follows:
main.m52 chars4 lines
Where index
is the loop variable that takes on each value in values
in succession.
Here is an example where we will use for loop to iterate over matrix elements:
main.m241 chars10 lines
In the above example, we have two nested for loops. The outer loop prints the row index and the inner loop prints the column index along with the corresponding matrix value.
You can replace the fprintf
statement with any desired code block to execute inside the loop.
gistlibby LogSnag