+ 1
Assertion is used to terminate the program while break is used to terminate loop, am i right? Or Both are interchangeable?
4 Respuestas
+ 4
Assertion is used to be sure of a condition in your programme. And the break statement are used to break out of a loop.
They are NOT interchangeable.
+ 4
More to the point, assertions are used to verify invariants, i.e., conditions that must hold true for the program to proceed. You should not use assertions to exit your program normally nor to check for "normal" error conditions such as invalid user input. Those should be anticipated by the program flow or handled with specific exceptions. Use assertions to terminate the program in case something impossible happens that can never be recovered from, such as the length of a list being negative or conditions of a similar caliber.
+ 2
yes you are right
0
Thanks Phipps for the details :)