Control Flow Statement :
In Java, control flow statements determine the order in which instructions are executed in a program.
There are three main types of control flow statements in Java:
Conditional (Decision-Making) Statements :
if statement :
These statements execute certain blocks of code only if a condition is true.
else statement :
Executes one block if the condition is true, otherwise executes the else block.
if-else-if ladder :
Used to check multiple conditions.
switch statement :
The switch case is used for decision-making when we need to execute one block of code out of many options based on a single value.
Looping (Iteration) Statements :
These statements repeat a block of code until a condition is false.
for loop :
The for loop is used when we need to repeat a block of code multiple times.
while loop :
The while loop is used when we need to repeat a block of code multiple times.
do-while loop :
Executes the loop at least once, then checks the condition.
Jump Statements :
Used to change the normal flow of the program.
break :
Exits from the loop or switch immediately.
continue :
Skips the current iteration and moves to the next iteration.
Switch Case :
The switch case is used for decision-making when we need to execute one block of code out of many options based on a single value.
Switch case supported these data types like int,char,byte,short in java 1.0 version.
In java 7th version, switch case supported String data types also.
The default is a special case block that executes if none of the case values match the given expression.
Top comments (0)