Overview - Range operator (..) and in operator
What is it?
The range operator (..) in Kotlin creates a sequence of values between two endpoints, including both ends. The in operator checks if a value exists within a range or collection. Together, they let you easily work with sequences of numbers or characters and test membership in those sequences. This makes tasks like loops and condition checks simpler and clearer.
Why it matters
Without the range and in operators, checking if a value falls between two points or iterating over a sequence would require more code and be harder to read. These operators make code shorter, easier to understand, and less error-prone. They help programmers express ideas like "from 1 to 10" or "is this letter between 'a' and 'z'?" naturally, improving productivity and reducing bugs.
Where it fits
Before learning ranges and the in operator, you should understand basic Kotlin syntax, variables, and simple conditionals. After mastering these, you can explore loops, collections, and more advanced Kotlin features like sequences and lambdas that often use ranges and membership checks.