Lesson 4
Repeated Practice Makes Perfect
Chapter 5: Breaking the flow
Altering the flow of loops
In the good old days, programmers can arbitrarily ‘jump’ to different lines in code with a goto
statement. This made it hard to read, understand and debug codes. This is generally considered a very bad thing nowadays, and most modern programming languages do not even provide this statement.
In (strict) structured programming, there is a rule that each building block must have only one entry point and one exit point. This prevents programmers from ‘jumping’ around the code to anywhere they like.
However, sometimes it is easier to allow the programmer to break this rule to a certain extent. Such codes are sometimes easier to read than a strictly structured programming style.
In this chapter, we will explore the break
statement that allows programmers to ‘interrupt’ the normal flow of a loop.