0
0
Kotlinprogramming~5 mins

Range operator (..) and in operator in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the range operator .. do in Kotlin?
The range operator .. creates a range of values from a start to an end, including both ends. For example, 1..5 means numbers 1, 2, 3, 4, and 5.
Click to reveal answer
beginner
How do you check if a value is inside a range in Kotlin?
You use the in operator. For example, 3 in 1..5 checks if 3 is between 1 and 5 (inclusive). It returns true if yes, false if no.
Click to reveal answer
beginner
What will this code print?<br>
for (i in 1..3) {
    println(i)
}
It will print:<br>1<br>2<br>3<br>Because the loop goes through the range from 1 to 3, including both ends.
Click to reveal answer
intermediate
Can the in operator be used with characters in Kotlin?
Yes! You can check if a character is inside a range of characters. For example, 'b' in 'a'..'d' returns true because 'b' is between 'a' and 'd'.
Click to reveal answer
intermediate
What does 5 !in 1..4 mean in Kotlin?
It means 5 is NOT in the range from 1 to 4. The !in operator checks if a value is outside the range. Here, it returns true because 5 is not between 1 and 4.
Click to reveal answer
What does 1..5 represent in Kotlin?
AA list of numbers from 1 to 4
BA range including numbers 1 to 5
CA range excluding 5
DA function call
What is the result of 3 in 1..5?
Afalse
BError
Ctrue
Dnull
Which operator checks if a value is NOT in a range?
Ain
B..
C!=
D!in
What will this print?<br>for (c in 'a'..'c') println(c)
Aa b c
Ba b
Cb c
Da c
Is 10 in 1..9 true or false?
Afalse
Btrue
CError
DDepends on context
Explain how the range operator .. works in Kotlin and give an example.
Think about counting numbers from one to another.
You got /3 concepts.
    Describe how to use the in operator to check if a value is inside a range.
    It's like asking if something is inside a box.
    You got /3 concepts.