Kotlin Ranges
Kotlin Ranges
In Kotlin, ranges are used to represent a sequence of values. They are commonly used with loops, conditions, and collections.
1. Basic Range (..)
The .. operator creates a range including both start and end values.
Output:
2. until Range (End Not Included)
Output:
3. Reverse Range (downTo)
4. Step in Range (step)
Output:
5. Character Range
6. Check Value in Range (in / !in)
7. Ranges with when
8. Floating-Point Ranges (Not Directly Supported)
❌ This does NOT work:
✅ Alternative:
9. Useful Range Properties
Summary
..→ inclusive rangeuntil→ excludes end valuedownTo→ reverse rangestep→ custom incrementWorks with
for,if,when
