Here's a MATLAB program that uses a while loop, if statement, and break statement to find the summation of numbers greater than 5 from 1 to 10:
main.m362 chars20 lines
This program will output:
main.m60 chars3 lines
The program checks if the current number is greater than 5 using the if
statement. If the condition is true, the number is added to the sum. The while
loop continues until the counter n
reaches 10. The break
statement is not needed in this case because the loop will naturally terminate when n
exceeds 10.
gistlibby LogSnag