![]() ![]() X !in 1.10 (As explained, this code would check x’s value against the number and return true if it doesnot exists). To check if the x doesnot belongs to range 1 to 10, we will write as: In certain cases if you wish to use check if the number doesnot exist in the range a simple not (!) operator would be helping us. X in 1.10 (this would return if the variable x has value in between the range) To check if a number x say belongs to range we can simply use it as: To check if a number exists in the range or not, Kotlin has given us another keyword which will help us identify if the number falls in the mentioned range or not and that keyword, we call it as in. So 1.10 would mean number from 1 till 10. is a range in simple terms it point to both the number being inclusive. When defining the limit or the exit criteria in case of Kotlin, we can use a simple operator which defines from condition and the exit condition. It provides you the functionality to rerun the same lines of code again and again but has certain advantages which reduce the code making it easier for the developer and hence improves efficiency.īefore we demo the Kotlin’s for, let’s have a look at some unique features offered by the Kotlin language: Kotlin Range Kotlin for loop does exactly the same for us. ![]() Before we jump on see what Kotlin has to offer in terms of for loop, let’s first recap the one we have used in Java.Ī typical Java for loop would like below: for (int i = 0 i<10 i++) and if the loop is having a single line of code we simply mention it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |