Skip to main content

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.

The ..< operator is the half-open range operator in Swift. It constructs a mathematical range that includes its lower bound but strictly excludes its upper bound.

Syntax Forms

The operator functions in two distinct arities: binary (two-sided) and prefix (one-sided).
// Binary (Two-sided)
let lowerBound = 0
let upperBound = 5
let twoSidedRange = lowerBound..<upperBound

// Prefix (One-sided)
let oneSidedRange = ..<upperBound

Type Signatures and Protocols

The types generated by the ..< operator depend on its arity. The generic Bound type provided to the operator must conform to the Comparable protocol.
  • Binary Form: Evaluates to a Range<Bound> structure. It requires both a lower and an upper bound.
  • Prefix Form: Evaluates to a PartialRangeUpTo<Bound> structure. It requires only an upper bound, implicitly extending infinitely downward.

Evaluation Rules

  1. Bound Relationship: For the binary form, the lowerBound must be less than or equal to the upperBound (lowerBound <= upperBound). A runtime crash occurs if the lower bound exceeds the upper bound.
  2. Empty Ranges: If lowerBound is exactly equal to upperBound, the resulting Range is empty.
  3. Exclusivity: The upperBound is never a member of the resulting range. Evaluating range.contains(upperBound) will always return false.
  4. Postfix Restriction: Unlike the closed range operator (...), the half-open range operator (..<) cannot be used as a postfix operator. Swift does not support a half-open PartialRangeFrom because a range extending infinitely upward has no defined upper bound to exclude.
Master Swift with Deep Grasping Methodology!Learn More