<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Range",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sn"
  },
  "title" : "Range"
}
-->

# Range

A half-open interval from a lower bound up to, but not including, an upper
bound.

```
@frozen struct Range<Bound> where Bound : Comparable
```

## Overview

You create a `Range` instance by using the half-open range operator
(`..<`).

```
let underFive = 0.0..<5.0
```

You can use a `Range` instance to quickly check if a value is contained in
a particular range of values. For example:

```
underFive.contains(3.14)
// true
underFive.contains(6.28)
// false
underFive.contains(5.0)
// false
```

`Range` instances can represent an empty interval, unlike `ClosedRange`.

```
let empty = 0.0..<0.0
empty.contains(0.0)
// false
empty.isEmpty
// true
```

## Using a Range as a Collection of Consecutive Values

When a range uses integers as its lower and upper bounds, or any other type
that conforms to the `Strideable` protocol with an integer stride, you can
use that range in a `for`-`in` loop or with any sequence or collection
method. The elements of the range are the consecutive values from its
lower bound up to, but not including, its upper bound.

```
for n in 3..<5 {
    print(n)
}
// Prints "3"
// Prints "4"
```

Because floating-point types such as `Float` and `Double` are their own
`Stride` types, they cannot be used as the bounds of a countable range. If
you need to iterate over consecutive floating-point values, see the
`stride(from:to:by:)` function.

## Topics

### Creating a Range

Create a new range using the half-open range operator (`..<`).

[`..<(_:_:)`](/documentation/Swift/Comparable/.._(_:_:))

Returns a half-open range that contains its lower bound but not its upper
bound.

### Converting Ranges

[`relative(to:)`](/documentation/Swift/Range/relative(to:))

Returns the range of indices described by this range expression within
the given collection.

[`init(_:in:)`](/documentation/Swift/Range/init(_:in:)-5cclx)

[`init(_:in:)`](/documentation/Swift/Range/init(_:in:)-5qfor)

### Inspecting a Range

[`isEmpty`](/documentation/Swift/Range/isEmpty)

A Boolean value indicating whether the range contains no elements.

[`lowerBound`](/documentation/Swift/Range/lowerBound)

The range’s lower bound.

[`upperBound`](/documentation/Swift/Range/upperBound)

The range’s upper bound.

### Checking for Containment

[`~=(_:_:)`](/documentation/Swift/Range/~=(_:_:))

Returns a Boolean value indicating whether a value is included in a
range.

### Clamping a Range

[`clamped(to:)`](/documentation/Swift/Range/clamped(to:))

Returns a copy of this range clamped to the given limiting range.

### Working with Foundation Ranges

[`init(_:)`](/documentation/Swift/Range/init(_:)-15u6b)

[`init(_:)`](/documentation/Swift/Range/init(_:)-1q7lu)

### Comparing Ranges

[`==(_:_:)`](/documentation/Swift/Range/==(_:_:))

Returns a Boolean value indicating whether two ranges are equal.

[`!=(_:_:)`](/documentation/Swift/Range/!=(_:_:))

Returns a Boolean value indicating whether two values are not equal.

[`overlaps(_:)`](/documentation/Swift/Range/overlaps(_:)-7osha)

Returns a Boolean value indicating whether this range and the given range
contain an element in common.

[`overlaps(_:)`](/documentation/Swift/Range/overlaps(_:)-9fkb2)

Returns a Boolean value indicating whether this range and the given closed
range contain an element in common.

### Manipulating Indices

[`hash(into:)`](/documentation/Swift/Range/hash(into:))

Hashes the essential components of this value by feeding them into the
given hasher.

### Describing a Range

[`description`](/documentation/Swift/Range/description)

A textual representation of the range.

[`debugDescription`](/documentation/Swift/Range/debugDescription)

A textual representation of the range, suitable for debugging.

[`customMirror`](/documentation/Swift/Range/customMirror)

The custom mirror for this instance.

### Encoding and Decoding a Range

[`encode(to:)`](/documentation/Swift/Range/encode(to:))

Encodes this value into the given encoder.

[`init(from:)`](/documentation/Swift/Range/init(from:))

Creates a new instance by decoding from the given decoder.

### Infrequently Used Functionality

[`init(uncheckedBounds:)`](/documentation/Swift/Range/init(uncheckedBounds:))

Creates an instance with the given bounds.

[`hashValue`](/documentation/Swift/Range/hashValue)

The hash value.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)
