---
title: Range
framework: swift
role: symbol
role_heading: Structure
path: swift/range
---

# Range

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

## Declaration

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

## Overview

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

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

### Converting Ranges

- [relative(to:)](swift/range/relative(to:).md)
- [init(_:in:)](swift/range/init(_:in:)-5cclx.md)
- [init(_:in:)](swift/range/init(_:in:)-5qfor.md)

### Inspecting a Range

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

### Checking for Containment

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

### Clamping a Range

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

### Working with Foundation Ranges

- [init(_:)](swift/range/init(_:)-15u6b.md)
- [init(_:)](swift/range/init(_:)-1q7lu.md)

### Comparing Ranges

- [==(_:_:)](swift/range/==(_:_:).md)
- [!=(_:_:)](swift/range/!=(_:_:).md)
- [overlaps(_:)](swift/range/overlaps(_:)-7osha.md)
- [overlaps(_:)](swift/range/overlaps(_:)-9fkb2.md)

### Manipulating Indices

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

### Describing a Range

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

### Encoding and Decoding a Range

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

### Infrequently Used Functionality

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

### Initializers

- [init(_:)](swift/range/init(_:)-35b1j.md)
- [init(_:)](swift/range/init(_:)-79g1a.md)
- [init(_:in:)](swift/range/init(_:in:)-24465.md)
- [init(_:in:)](swift/range/init(_:in:)-612lr.md)
- [init(_:in:)](swift/range/init(_:in:)-75xo3.md)
- [init(_:in:)](swift/range/init(_:in:)-9vre5.md)

### Instance Methods

- [contains(_:)](swift/range/contains(_:)-4xxju.md)
- [contains(_:)](swift/range/contains(_:)-680jp.md)
- [contains(_:)](swift/range/contains(_:)-76nb4.md)
- [formatted()](swift/range/formatted().md)
- [formatted(_:)](swift/range/formatted(_:).md)
- [formatted(date:time:)](swift/range/formatted(date:time:).md)
- [isValid(within:)](swift/range/isvalid(within:)-2fba2.md)
- [isValid(within:)](swift/range/isvalid(within:)-8h4h8.md)

### Type Methods

- [upToNextMajor(from:)](swift/range/uptonextmajor(from:).md)
- [upToNextMinor(from:)](swift/range/uptonextminor(from:).md)

### Default Implementations

- [BidirectionalCollection Implementations](swift/range/bidirectionalcollection-implementations.md)
- [Collection Implementations](swift/range/collection-implementations.md)
- [CustomDebugStringConvertible Implementations](swift/range/customdebugstringconvertible-implementations.md)
- [CustomReflectable Implementations](swift/range/customreflectable-implementations.md)
- [CustomStringConvertible Implementations](swift/range/customstringconvertible-implementations.md)
- [Decodable Implementations](swift/range/decodable-implementations.md)
- [Encodable Implementations](swift/range/encodable-implementations.md)
- [Equatable Implementations](swift/range/equatable-implementations.md)
- [Hashable Implementations](swift/range/hashable-implementations.md)
- [RangeExpression Implementations](swift/range/rangeexpression-implementations.md)
- [Sequence Implementations](swift/range/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)
- [RandomAccessCollection](swift/randomaccesscollection.md)
- [RangeExpression](swift/rangeexpression.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)

## See Also

### Ranges

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