CHAPTER 4

CONTROL STRUCTURES

In Chapter 3, we saw a few simple statements. In a program, these statements are executed one after the other. However, these statements are not sufficient to effectively solve the problems. To solve these problems, flow control statements are used. When we use them, statement to be executed need not be the very next statement. This gives tremendous power to the code.

Java supports many flow control statements. We can group these statements in the following manner.

  1. The first group consists of decision-making statements. Examples areIf-else and switch-case statements.
  2. The second group consists of looping statements. Examples arewhile, do-while, and for statements.
  3. The third group consists of branching statements Examples ...

Get Programming with Java 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.