what is function of break in this example?
Show older comments
for x=2:17
if gcd(160,x)==1
e=x;
break
end
d=1;
end
Answers (1)
Geoff Hayes
on 28 Oct 2015
0 votes
Gauri - break is used to terminate execution of the for loop. In this case, when the greatest comman divisor of 160 and x is one, then there is no need to continue intreating.
Try using the MATLAB debugger to step through the code and observe what happens.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!