Three Forms of Control
Structured programming promotes simplicity. Only three forms of control are needed to implement an algorithm:
• sequence
• selection
• repetition
The sequence structure is trivial. Simply list the statements to execute in the order in which they should execute. Selection is implemented in one of three ways:
• if
statement (single selection)
• if
...else
statement (double selection)
• switch
statement (multiple selection)
In fact, it’s straightforward to prove that the simple if
statement is sufficient to provide any form of selection—everything that can be done with the if
...else
statement and the switch
statement can be implemented by combining if
statements (although perhaps not as clearly and efficiently).
Repetition ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.