Control Structures in Java

The control structures in java will be used to modify the sequential flow of a program. That is, the order in which the instructions on it are executed.

In a program, instructions are executed from top to bottom, and from left to right, depending on the order in which they appear. The different instruction blocks of our program will follow this sequential flow to execute the instructions. The instruction blocks shall be delimited by braces brackets:

Block {
instruction 1;
instruction 2; instruction 3;
instruction 4;
}

However, in some cases we will need to break this sequential flow. Reasons for that can be many, we may need to make a decision between one or several possible options, or maybe we need to perform some instructions several times. Therefore, we need certain structures that allow us to interrupt the sequential flow of the program, and move on to execute other blocks of code.

In this post, we will study the operation of the following control structures:

  • Decision making: if-then, if-then-else, switch.
  • Loop: for, while, do-while

Decision making structures

Continue reading Control Structures in Java