Conditional Statements if else elseif in Java

In this class, We discuss Conditional Statements if else elseif in Java.

The reader should have prior knowledge of variables and data types in Java. Click Here.

Conditional Statements:

if condition

In this class, we discuss execution flow with an example.

The execution flow is very, very important to understand.

If you want to write the code, Understanding the execution flow is needed.

Example:

public static void main(String args[])

{

int a= 20, b = 30;

if(a<b)

{

System.out.println(a+”<“+b);

a=a+1;

}

System.out.println(“outside if”);

}

Explanation:

if(condition)

if the condition is true, the block of code mentioned for if will execute.

After executing the if statement’s body, execution continues with the remaining code.

If the condition is false execution, skip the body of the if statement and continue with the remaining code.

If else statement:

The below code shows the if else example.

If the condition in the if statement is true, then execute the body of the if statement; otherwise, execute the body of the else.

if elseif else statement

The below code shows the if elseif example.

First, if the condition is false, then check the elseif condition.

If the elseif is false, then the next elseif condition.

If all the if conditions are false, then the else block will execute.