Kotlin - Nested if Statement Example

When there is an if statement inside another if statement then it is called the nested if statement.

Syntax:

if(condition_1) {
   Statement1(s);

   if(condition_2) {
      Statement2(s);
   }
}

Kotlin - Nested if Statement Example

package net.javaguides.kotlin

fun main(args: Array < String > ) {

    var num = 50;
    if (num < 100) {
        System.out.println("number is less than 100");
        if (num == 50) {
            System.out.println("number equal to 50");
            if (num > 40) {
                System.out.println("number is greater than 40");
            }
        }
    }

}
Output:
number is less than 100
number equal to 50
number is greater than 40



Comments