Skip to content

Commit

Permalink
Add repeat(…)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Dec 5, 2024
1 parent 12f546e commit 972997d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages_v5/example.candy
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ fun loop(body: () Nothing) {
body()
loop(body)
}
fun repeat(times: Int, body: () Nothing) {
needs(times.isNonNegative())
switch times.isGreaterThan(0) {
false => {},
true => {
body()
repeat(times.subtract(1), body)
},
}
}

struct List[T] = builtin
fun listFilled[T](length: Int, item: T) List[T] {
Expand Down Expand Up @@ -549,6 +559,8 @@ fun main() Int {
let addCaptured = (x: Int) { x.add(foo) }
print("addCaptured(1) = {addCaptured(1).toText()}")

repeat(3, () { print("Hello, World!") })

0
}

Expand Down

0 comments on commit 972997d

Please sign in to comment.