Post

KotlinKotlin

A
Anusha V

Posted on 26th April 2024|44 views

0
votes

Kotlin Switch Statement

What is the switch statement in kotlin?

Answers
P
Sowjanya Kodiganti

Posted on 26th April 2024

A standard switch statement is just a statement that substitutes a range of simple if/else that performs necessary checks but it cannot replace all kind of if/else series it can only replace those which compare a value with some constant.

A small example of a switch statement is given below:

switch(choice)

{

case 1:

system.out.println(“fruits”);

case 2:

system.out.println(“leaves”);

case3:

system.out.println(“branches”);

default:

system.out.println(“not a tree”);

}

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos