Lesson 11 Programming in Kotlin

in #programming7 years ago

Lesson 11 Programming in Kotlin 

![Kotlin-logo.png]()

Conditional statement : when 

we use (when) we have multiple cases with a number of values ​​for the variable 

We will explain the idea through the following example:     

fun main (args:Array <String>){  

     printl ("enter a number:")  

     var number:Int = readLine()!!.toInt()  

     when (number){  

           1 ->{ 

              print("A") 

             }  

            2,3->{  

                 print("B")  

               }   

          In  4..10-> {

               print("C") 

              }else{  

                    print ("out of range")  

              } 

}
In this example we asked the user to enter the number and value then we stored it in the variable number  

Then we used the conditional statement when to execute a program command according to the value of the variable entered 

If the value of the entered number is equal to 1, the order to be executed is 

print ("A")  

If it is  2 or 3, then it will be implemented  

print ("B")  

But if its value is between 4 and 10, then it will be implemented  

print ("C")  

else  the result will be

 out of range  

We  notice that the conditional statement is very much like if-else if-else