Java Control Statements

There are three types of control flow statements in java as below. Control statements that can be used to control the flow of Java code

  • Decision Making statements
  • Loop statements
  • Jump statements

1. Decision Making statements

Decision-making statements evaluate the Boolean expression and control the program flow depending upon the result of the condition provided. There are two types of decision-making statements in Java as below

  • If statement - An if statement consists of a boolean expression followed by one or more statements.
  • switch statement. - The switch statement selects one of many code blocks to be executed

2. Loop statements

loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in java. Java provides three types of loops as below

  • for loop  - Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.
  • while loop  - The while loop is also used to iterate over the number of statements multiple times. It tests the condition before executing the loop body.
  • do-while loop - The do-while loop checks the condition at the end of the loop after executing the loop statements. When the number of iteration is not known and we have to execute the loop at least once, we can use do-while loop.

3. Jump statements

Jump statements are used to transfer the control of the program to the specific statements. In other words, jump statements transfer the execution control to the other part of the program. There are two types of jump statements in Java as below

  • break - The break statement can also be used to jump out of a loop.
  • continue -  It skips the specific part of the loop and jumps to the next iteration of the loop immediately.

 

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

45966