One of the ways to ensure following the structured programming paradigm is by ha
ID: 649856 • Letter: O
Question
One of the ways to ensure following the structured programming paradigm is by having all control flows having only one entry and one exit point. Does skipping iterations by using break and continue in languages like Java count as a second exit point (like a GOTO-statement) or not?
I am aware that Java has no (working) goto statement but a break and continue. The question was whether using them violates the structured programming paradigm or not, i.e. is it bad code style or not (in all languages having break and continue, not just Java).
Explanation / Answer
That of course depends on how exactly we define structured programming. We can look to the research papers that coined the phrase, such as the 1966 Structured Programming Theorem. Structured programming, as defined in these papers, would not permit partial execution of a loop body, and therefore neither a break, continue, return or throw statement (nor any exceptions thrown by the JVM).
All of these language features were invented after structured programming, and to address perceived deficiencies of structured programming (in its original definition). Whether these amendments comply with the spirit of structured programming (or equivalently, whether a modern definition of structured programming should encompass these features) has been the topic of some debate, see for instance the 1995 paper Loop Exits and Structured Programming: Reopening the Debate.
Personally, I find applying this 1966 programming technique, ground breaking as it was at the time, verbatim to a modern programming language such as Java an undertaking of very questionable benefit, not the least because structured programming (in its original definition) does not permit exceptions, but exceptions are an integral part of the Java language.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.