---
title: ClosedRange
framework: swift
role: symbol
role_heading: Structure
path: swift/closedrange
---

# ClosedRange

An interval from a lower bound up to, and including, an upper bound.

## Declaration

```swift
@frozen struct ClosedRange<Bound> where Bound : Comparable
```

## Overview

Overview You create a ClosedRange instance by using the closed range operator (...). let throughFive = 0...5 A ClosedRange instance contains both its lower bound and its upper bound. throughFive.contains(3) // true throughFive.contains(10) // false throughFive.contains(5) // true Because a closed range includes its upper bound, a closed range whose lower bound is equal to the upper bound contains that value. Therefore, a ClosedRange instance cannot represent an empty range. let zeroInclusive = 0...0 zeroInclusive.contains(0) // true zeroInclusive.isEmpty // false Using a Closed Range as a Collection of Consecutive Values When a closed 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, and including, its upper bound. for n in 3...5 {     print(n) } // Prints "3" // Prints "4" // Prints "5" 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:through:by:) function.

## Topics

### Creating a Range

- [...(_:_:)](swift/comparable/'...(_:_:).md)

### Converting Ranges

- [relative(to:)](swift/closedrange/relative(to:).md)

### Inspecting a Range

- [isEmpty](swift/closedrange/isempty.md)
- [lowerBound](swift/closedrange/lowerbound.md)
- [upperBound](swift/closedrange/upperbound.md)

### Checking for Containment

- [~=(_:_:)](swift/closedrange/~=(_:_:).md)

### Clamping a Range

- [clamped(to:)](swift/closedrange/clamped(to:).md)

### Comparing Ranges

- [==(_:_:)](swift/closedrange/==(_:_:).md)
- [!=(_:_:)](swift/closedrange/!=(_:_:).md)
- [overlaps(_:)](swift/closedrange/overlaps(_:)-947dt.md)
- [overlaps(_:)](swift/closedrange/overlaps(_:)-7dfep.md)

### Manipulating Indices

- [hash(into:)](swift/closedrange/hash(into:).md)

### Describing a Range

- [description](swift/closedrange/description.md)
- [debugDescription](swift/closedrange/debugdescription.md)
- [customMirror](swift/closedrange/custommirror.md)

### Encoding and Decoding a Range

- [encode(to:)](swift/closedrange/encode(to:).md)
- [init(from:)](swift/closedrange/init(from:).md)

### Infrequently Used Functionality

- [init(uncheckedBounds:)](swift/closedrange/init(uncheckedbounds:).md)
- [hashValue](swift/closedrange/hashvalue.md)

### Initializers

- [init(_:)](swift/closedrange/init(_:)-er19.md)
- [init(_:)](swift/closedrange/init(_:)-rhzn.md)

### Instance Methods

- [contains(_:)](swift/closedrange/contains(_:)-29358.md)
- [contains(_:)](swift/closedrange/contains(_:)-822cl.md)

### Default Implementations

- [BidirectionalCollection Implementations](swift/closedrange/bidirectionalcollection-implementations.md)
- [Collection Implementations](swift/closedrange/collection-implementations.md)
- [CustomDebugStringConvertible Implementations](swift/closedrange/customdebugstringconvertible-implementations.md)
- [CustomReflectable Implementations](swift/closedrange/customreflectable-implementations.md)
- [CustomStringConvertible Implementations](swift/closedrange/customstringconvertible-implementations.md)
- [Decodable Implementations](swift/closedrange/decodable-implementations.md)
- [Encodable Implementations](swift/closedrange/encodable-implementations.md)
- [Equatable Implementations](swift/closedrange/equatable-implementations.md)
- [Hashable Implementations](swift/closedrange/hashable-implementations.md)
- [RangeExpression Implementations](swift/closedrange/rangeexpression-implementations.md)
- [Sequence Implementations](swift/closedrange/sequence-implementations.md)

## Relationships

### Conforms To

- [BNNSGraph.Builder.SliceIndex](accelerate/bnnsgraph/builder/sliceindex.md)
- [BidirectionalCollection](swift/bidirectionalcollection.md)
- [Collection](swift/collection.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [CustomTestStringConvertible](testing/customteststringconvertible.md)
- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [MLShapedArrayRangeExpression](coreml/mlshapedarrayrangeexpression.md)
- [MLTensorRangeExpression](coreml/mltensorrangeexpression.md)
- [NDArray.RangeExpression](coreai/ndarray/rangeexpression.md)
- [PositionScaleRange](charts/positionscalerange.md)
- [RandomAccessCollection](swift/randomaccesscollection.md)
- [RangeExpression](swift/rangeexpression.md)
- [ScaleDomain](charts/scaledomain.md)
- [ScaleRange](charts/scalerange.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)

## See Also

### Ranges

- [..<(_:_:)](swift/comparable/'.._(_:_:).md)
- [Range](swift/range.md)
- [RangeSet](swift/rangeset.md)
- [...(_:_:)](swift/comparable/'...(_:_:).md)
