if, nested if, if else if ladder, selection and branch control statements in Java

if statement: if is a selection and branch conditional statement in Java. It is used to control the flow of a Java program.

Syntax:

if (condition) statement1;

else statement2;

Nested if: if statement inside if statement is known as nested if.

For Example:

if(a == 5) {

if(b > 10)

x = y;

else y = z;

}

else x = z;

if else if ladder: In a if else if ladder the execution flow goes from top to down.

Syntax:

if(condition)

statement;

else if(condition)

statement;

else if(condition)

statement;

else

statement;

Leave a Reply