Break Statement In C++
Break Statement ?
Break Statement is a loop control statement which is used to terminate the loop.
The break statement is used in two situations:
1) When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.
2) It can be used to terminate a case in the switch statement (covered in the next chapter).
Break Statement :
➦In real practice, break statement is almost always used inside the body of conditional statement (if...else) inside the loop.
➦Basically break statements are used in the situations when we are not sure about the actual number of iterations for the loop or we want to terminate the loop based on some condition.
Enter a number: 4 Enter a number: 3.4 Enter a number: 6.7 Enter a number: -4.5 Enter a number: 0 Sum = 9.6
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15