break Statement
Get introduced to the break statement in C++.
We'll cover the following...
Introduction
Suppose you have a coupon to buy five ice-creams free of cost, but the ice-cream man only has three ice-creams. In this case, while you can have some free ice-creams, the ice-cream man eventually runs out of ice-creams before you have utilized all your coupons.
In programming, we can use the break
statement for such situations. The break
statement can be used to jump out of the loop immediately when a particular condition evaluates to true.
The break statement terminates the loop and transfers control to the very next statement after the loop body.