Kotlin if expression

In this tutorial you will learn about the Kotlin if expression and its application with practical example.

Kotlin if Expression

Block of statement executed only when a specified condition is true.

Syntax:-

Example:-

Output:-

Kotlin if…else Expression

When we want to execute some block of code if a condition is true and another block of code if a condition is false, In such a case we use if….else statement.

Syntax:-

Example:-

Output:-

Kotlin if..else..if Ladder Expression

The if..else..if Ladder statement is used to select one of among several blocks of code to be executed.

Example:-

Output:-

Kotlin Nested if Expression

When there is an if statement inside another if statement then it is known as nested if else.

Example:-

Output:-

 

In this tutorial we have learn about the Kotlin if expression and its application with practical example. I hope you will like this tutorial.