The number of times the loop will iterate depends on the value returned by the randi
function. Since randi(10)
returns a random integer between 1 and 10, the loop could iterate between 1 and 10 times. To be precise, the loop will iterate ind
number of times, where ind
is the random integer returned by randi(10)
and starts with a value of 1.
Note that the loop body should contain some code to change the value of ind
at some point, otherwise the loop will iterate indefinitely.
Here's an example of how to use this loop in MATLAB:
main.m110 chars6 lines
This loop will display the value of ind
on each iteration, starting with the random integer returned by randi(10)
and ending when ind = 11
. The loop will iterate between 1 and 10 times, depending on the value of ind
.
gistlibby LogSnag