

By default the value of step is 1 so when we create range 1.10, it is 1, 2, 3.10. So, you can only use a switch to perform an action when one specific variable has a certain precise value. With the help of step () function we can define the interval between the values. However it cannot replace all sort of if/else sequences but just those which compare a value with some constant. Syntax of ntains () The syntax of ntains () function is ntains (element) Return Value Example 1: Check if List Contains Element In this example, we will take a list of strings, list1, and a string, element. One of the most useful improvement, especially if you come from Java, is the when construct.Ī traditional switch is basically just a statement that can substitute a series of simple if/else that make basic checks. The Kotlin ntains () function returns true if element is found in the list, else false.


Kotlin is full of these pragmatic improvements, getting its user a language that just feel good to use. There are two kinds of innovation: new perspectives that changes how we look at things and pragmatic improvements that changes how we do things.
