Mojo function
repeat
repeat[ElementType: Copyable & Movable](element: ElementType, *, times: Int) -> _RepeatIterator[ElementType]
Constructs an iterator that repeats the given element a specified number of times.
This function creates an iterator that returns the same element over and over for the specified number of times.
Examples:
# Repeat a value 3 times
var it = repeat(42, times=3)
for val in it:
print(val) # Prints: 42, 42, 42
# Repeat a string 5 times
var str_it = repeat("hello", times=5)
for s in str_it:
print(s) # Prints: hello, hello, hello, hello, helloParameters:
Args:
- โelement (
ElementType): The element to repeat. - โtimes (
Int): The number of times to repeat the element.
Returns:
_RepeatIterator: An iterator that repeats the element the specified number of times.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!