![]() ![]() Package kotlin.ranges /** * A range of values of type `Char`. Keep smiling, and have a good day.ClosedRange is further extended by CharRange, IntRange and LongRange which provides the functionality of Iterable also along with closed range which is used by for loops. In the next lesson, we will be learning about implementing these ranges and the double dot operators with the help of loops. Comparison operators have the same syntax and purpose as in many other languages. The result of any comparison operator is a Boolean value true or false. This means they require two operands on the left and right sides. So here we are, we are done with the ranges and the double dot operators. To compare two values, the Kotlin language uses comparison operators. And similarly, for the descending order, you can use the downTo function and use the step with it. Same way instead of double dot operator you can use rangeTo to define the steps for your ranges. Which means at the step of 2, the values will be assigned to the ranges. It means 1, the second one will be ignored, 3, fourth one will be ignored, and then 5. Let's say if we want 1, 3, and 5, 1, 3, and 5. Another way we can use these ranges and dot operators is if we want to have some steps in our ranges. These ranges and double dot operators will be very helpful when we use it with the loop. The value of this range will be varying from a, b, c, up to z. Here instead of integer we can also have the characters. And now the other representation of this means 5 down to the other int value or we can say the to value is 1. Say r3 =5.1 which will vary from 5, 4, 3, 2, 1. Now, what if we want the range in the descending order? It will be written like this. Same as the previous range, it is just a different representation. Another way you can represent this range of r1 is, this is the range of r2. So this is the double dot operator, and the range of variable is 1, which ends at 5. It will have the value, starting from 1 to 5. So here we have the variable r1, which has its range from 1 to 5. Let's say we have var range one, let me represent it as r1, is equal to 1.5. This is going to be a very short lesson starting with the ranges. Hello, in this lesson, we will be learning about ranges and double dot operators in Kotlin. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |