🐦 Kotlin
Beginner
What is a range in Kotlin?
Answer
A range in Kotlin represents an interval between two values, created with the .. operator: 1..10 creates an inclusive range from 1 to 10. Ranges work with any Comparable type, including characters and strings. For an exclusive end, use until: 0 until 10 (0 to 9). For descending ranges, use downTo: 10 downTo 1. You can also specify a step: 1..10 step 2 gives 1, 3, 5, 7, 9. Ranges integrate seamlessly with for loops and the in operator for membership checks.
Previous
What does the apply scope function do in Kotlin?
Next
What is a default parameter in Kotlin?