Create a nested for-loop script to iterate through all values of i=1:20 and j=1:20. Also start with a
running tally of total=0.
At each iteration, check the value of j. If j is divisible by 3, then do nothing and proceed to the next value of j. Next, if i x j is greater than 100, then stop processing the current j-based for-loop, and move on to the next value of i.
If both conditions have not been met, then add both i and j to the running tally called total. What is your final value for total at the end of your script? And how many times did MATLAB execute the break and continue statements in your program?
1
Expert's answer
2015-06-01T01:46:27-0400
Answer: total=0; for i=1:10 flagBreak=0; for j=1:20 if rem(j,3)==0 continue; else if i*j>100 flagBreak=1; break; else total=total+i+j; end end end if flagBreak==1 continue; end end total Result: 1586 Number of break: 5 Number of continue: 56
Comments
Leave a comment