Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

The Break keyword

The break keyword can exit the body loop whenever we specify. It is heavily used when we want to stop the loop process under a when condition is met, usually when an exception occurs.

There is no specific syntax, we just throw the word 'break' inside the body of the loop context and if the code finds itself inside there, and reaches the 'break' line the loop exits!

L-5. In the previous container problem. The captain is tremendously superstitious and will not accept the ship to travel if it contains more than 112 containers! Find a way to stop adding more containers when we reach the 112 containers and ship the shipment right away! You may want to apply what you have learned today.