<!--
{
  "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/repeatElement(_:count:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s13repeatElement_5counts8RepeatedVyxGx_SitlF"
  },
  "title" : "repeatElement(_:count:)"
}
-->

# repeatElement(_:count:)

Creates a collection containing the specified number of the given element.

```
func repeatElement<T>(_ element: T, count n: Int) -> Repeated<T>
```

## Parameters

`element`

The element to repeat.

`n`

The number of times to repeat `element`.

## Return Value

A collection that contains `count` elements that are all
`element`.

## Discussion

The following example creates a `Repeated<Int>` collection containing five
zeroes:

```
let zeroes = repeatElement(0, count: 5)
for x in zeroes {
    print(x)
}
// 0
// 0
// 0
// 0
// 0
```

---

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)