Day 15:
Java Control Statements:
Java compiler executes the code from Top to Bottom. However Java provides the statement to control the flow.
Categories of Control Statements in Java
2. Looping Statements
3.Jump Statements
1. Decision-Making Statements
As the name states, decision-making statements decide whether the block of code next to the statement or not. It works on the result of 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, i.e., If statement and switch statement.
if Statement
Executes a block of code if the condition is true.
Example:
if-else Statement
Provides an alternative path if the condition is false.
example:
if-else-if Ladder
Tests multiple conditions sequentially.
example:
Nested if:
In nested if-statements, the if statement can have an if inside another if .
switch Statement
Tests a variable against a list of values (cases) and executes the matching block.
Example:
Let's continue with the Looping statements tomorrow. Happy Learning :)