> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Range Until

The `..<` operator is the open-ended range operator in Kotlin, used to construct a range of values that includes the lower bound but strictly excludes the upper bound. It provides a mathematically intuitive representation of half-open intervals $[a, b)$ and serves as the native syntactic replacement for the `until` infix function.

## Syntax and Compilation

The operator is placed between the start and end bounds:

```kotlin theme={"dark"}
val range = start ..< end
```

During compilation, the Kotlin compiler desugars the `..<` operator into a method call to the `rangeUntil` operator function. The above syntax is strictly equivalent to:

```kotlin theme={"dark"}
val range = start.rangeUntil(end)
```

## Type System Integration

The behavior and return type of the `..<` operator depend on the operand types:

1. **Integral Types (`Int`, `Long`, `Short`, `Byte`, `Char`)**:

   For discrete integral types, the operator returns a standard `Iterable` progression (e.g., `IntRange`, `LongRange`). The standard library implementation of `rangeUntil` for these types explicitly guards against integer underflow. Rather than blindly calculating `end - 1` to find an inclusive upper bound, the function checks the exclusive bound against the type's minimum value (e.g., `if (to <= Int.MIN_VALUE) return IntRange.EMPTY`). This ensures that an expression like `0 ..< Int.MIN_VALUE` safely returns an empty range instead of underflowing to `Int.MAX_VALUE`.

   ```kotlin theme={"dark"}
   ```

val intRange: IntRange = 0 ..\< 10
val emptyRange: IntRange = 0 ..\< Int.MIN\_VALUE // Safely returns IntRange.EMPTY

````
2. **Floating-Point Types (`Float`, `Double`)**:

   Because `Float` and `Double` implement the `Comparable` interface, they automatically inherit the generic `Comparable<T>.rangeUntil` extension function from the Kotlin standard library. Expressions using `..<` with these types compile successfully and return an `OpenEndRange<Float>` or `OpenEndRange<Double>`.
   ```kotlin
val doubleRange: OpenEndRange<Double> = 1.0 ..< 2.0
````

## Operator Overloading and Custom Types

Any class that implements the `Comparable<T>` interface automatically supports the `..<` operator without requiring a manual implementation of the `rangeUntil` member function. The standard library provides the extension `operator fun <T : Comparable<T>> T.rangeUntil(that: T): OpenEndRange<T>`, which handles the boundary evaluation.

```kotlin theme={"dark"}
class Version(val major: Int, val minor: Int) : Comparable<Version> {
    override fun compareTo(other: Version): Int {
        return compareValuesBy(this, other, { it.major }, { it.minor })
    }
}

// Syntax visualization: Automatically supported via Comparable<T>.rangeUntil
val v1 = Version(1, 0)
val v2 = Version(2, 0)
val versionRange: OpenEndRange<Version> = v1 ..< v2
```

Explicit implementation of the `rangeUntil` operator function is only required for non-comparable types, or when a custom type needs to return a specialized discrete progression (such as a custom `Iterable` range) rather than the default continuous `OpenEndRange<T>`.

## Behavioral Characteristics

* **Ascending Order Only**: The `..<` operator strictly creates ascending ranges. If the left operand is greater than or equal to the right operand, the resulting range is empty (`isEmpty()` returns `true`).
* **Step Size**: For integral progressions, the default step size is `1`.
* **Interface Hierarchy**: The `OpenEndRange<T>` interface is distinct from `ClosedRange<T>` (which is generated by the `..` operator). `OpenEndRange` exposes an `endExclusive` property, whereas `ClosedRange` exposes an `endInclusive` property.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
