Complete the code to exit the loop when the value reaches 5.
for i = 1:10 if i == [1] break; end end
continue instead of break.The break statement stops the loop when i equals 5.
Complete the code to skip printing the number 3 using continue.
for i = 1:5 if i == [1] continue; end disp(i) end
break instead of continue.The continue statement skips the rest of the loop body when i is 3, so 3 is not printed.
Fix the error in the code to stop the loop when the sum exceeds 10.
sumVal = 0; for i = 1:10 sumVal = sumVal + i; if sumVal [1] 10 break; end end
< or == which do not stop at the right time.The loop should stop when the sum is greater than 10, so use >.
Fill both blanks to create a loop that skips even numbers and stops at 7.
for i = 1:10 if mod(i, 2) == [1] continue; end if i == [2] break; end disp(i) end
mod(i, 2) == 0 checks for even numbers to skip, and i == 7 stops the loop.
Fill all three blanks to print only odd numbers less than 10 and stop at 9.
for i = 1:15 if mod(i, [1]) == [2] disp(i) if i == [3] break; end end end
The code checks for odd numbers with mod(i, 2) == 1 and stops when i == 9.
