Monday, 11 December 2017

Kotlin: if-else if-else

By using if-else if-else construct, you can choose between number of alternatives.

An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions.

IfElseIf.kt
fun main(args: Array<String>) {
 var marks: Int = 65

 if (marks < 35)
  println("You are failed");
 else if (marks < 50)
  println("You are passed and got third class");
 else if (marks < 60)
  println("You are passed and got second class");
 else if (marks < 70)
  println("You are passed and got first class");
 else
  println("You are passed and got distinction");
}

Output

You are passed and got first class


Previous                                                 Next                                                 Home

No comments:

Post a Comment