Java Control Statements

Home / Core Java / Java Control Statements

Java Control Statements


Java Control Statements :

In Java, control statements are used to control the flow of execution in a program, allowing the programmer to dictate how the code behaves based on certain conditions.
These control statements can be categorized into three main types:
  • Decision-Making Statements
  • Loop Statements
  • Jump Statements


Decision-Making Statements:

  • if  Statements:  Used to make decisions based on conditions. It executes a block of code if a specified condition is true.
  • switch Statement:  Provides a way to select one of many code blocks to be executed, based on the value of a variable.


Loop Statements:

  • do-while Loop:  Executes a block of code repeatedly as long as a condition is true. The block is executed at least once, even if the condition is initially false.
  • while Loop:  Repeatedly executes a block of code as long as a specified condition is true. It checks the condition before entering the loop.
  • for Loop:  Used to execute a block of code a specified number of times, providing initialization, condition check, and iteration update.
  • for-each Loop:  Simplifies the iteration through arrays and collections by iterating through all elements of an array or collection.


Jump Statements:

  • break Statement: Terminates the loop or switch statement, transferring control to the statement immediately following the loop or switch.
  • continue Statement: Skips the current iteration in a loop and continues with the next iteration.