The break statement terminate the execution of a for loop or while loop. When a break statement is encountered, execution proceeds with the next statement outside of the loop. In nested loops, break exists from the innermost loop only.
Following are the points while using a break statement in MATLAB:
Flowdiagram of Break Statement
a = 6×6 82 17 70 54 54 10 27 18 70 66 33 27 60 43 64 41 11 16 3 10 4 82 62 29 43 60 7 72 78 45 32 48 32 97 43 53 program running smoothly program running smoothly program encounters the number 27, which is not useful for the current program; at index no.:2 so loop terminates now.....bye bye
a = 4×4 0.2398 -1.6118 0.8617 0.5812 -0.6904 -0.0245 0.0012 -2.1924 -0.6516 -1.9488 -0.0708 -2.3193 1.1921 1.0205 -2.4863 0.0799 negative number :-0.69036,found at index: 2,hence the program terminated
Program to terminate the flow of execution using the break statement.
Suppose we have a system that running on temperature variance. The temperature of the environment defines the working of the system. If the temperature of the environment passes beyond the hazardous limit, the program must stop the execution of the application that running the system.
The working temperature range varies according to some predefined conditions. So during summertime, when heat waves can damage the sophisticated system, or there is a drop in temperature below the specified limit during winter, we need to protect the system from getting it down.
The temperature range varies from -100° c to + 600°c.
The system is installed at different locations all over the world. Somewhere the temperature is measured in Celsius and somewhere it is measured in Fahrenheit. So we need to take care of these temperature units also.