Conditional Statements
in Java
Topics to be covered
1. Introduction to Conditional Statements
2. Types of Conditional Statements
a. if statement
b. Multiple use of if
c. if-else statement
d. Nested if statement
Mind Map
Control Statements
Sequential Conditional Iterative
Statements Statements Statements
Sequential Statements
Conditional Statements
Selection statements allow us to control the flow of program execution
on the basis of the conditions. The condition is an expression that
returns a boolean value.
Selection statements can be divided into the following categories:
a. The if statement
b. Multiple of if
c. The if-else statement
d. The if-else-if statement
if Conditional Statement
The if statement only executes when the specified condition is true. If
the condition is false and there is not else keyword then the first
contained statement will be skipped and execution continues with the
rest of the program.
The syntax is :
if(condition)
{
Set of statements;
}
if and only if Conditional Statement
The if and only if statement is used where two or more actions to be
performed depending upon the conditions.
The syntax is :
if(condition)
{
Set of statements;
}
if(condition)
{
Set of statements;
}
if else Conditional Statement
The if else statement only executes when either of the two actions are
to be performed depending upon certain conditions.
The syntax is :
if(condition)
{
Set of statements;
}
else
{
Set of statements;
}
if else if else Statement
It works with multiple conditions. Whenever the condition is true,
the associated statement will be executed and the remaining
conditions will be bypassed. If none:of the conditions are true then
the else block will execute The syntax is ->
if(condition)
statements;
else if (condition)
statements;
else if(condition)
statement;
else
statements;
if else if else Statement