Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix: clarify bounds of values in repeat statement (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota authored Aug 2, 2024
1 parent f4b9a10 commit 9655bac
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pages/book/statements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,24 @@ Conditionally repeat certain blocks of code multiple times.

### `repeat` [#repeat-loop]

The `repeat{:tact}` loop executes a block of code a specified number of times. Number of repetitions must be a non-negative $32$-bit [`Int{:tact}`][int]. Otherwise an error with the [exit code 5](/book/exit-codes#5), `Integer out of the expected range` would be thrown.
The `repeat{:tact}` loop executes a block of code a specified number of times. The number of repetitions should be given as a positive $32$-bit [`Int{:tact}`][int] in the inclusive range from $1$ to $2^{31} - 1$. If the value is greater, an error with the [exit code 5](/book/exit-codes#5), `Integer out of the expected range` would be thrown.

In the following example, code inside the loop will be executed $10$ times:
If the specified number of repetitions is equal to $0$ or any negative number in the inclusive range $-2^{256}$ to $-1$, it is ignored and the code block is not executed at all.

```tact
let twoPow: Int = 1;
repeat (10) { // repeat exactly 10 times
// Repeat exactly 10 times
repeat (10) {
twoPow *= 2;
}
// Skipped
repeat (-1) {
twoPow *= 3333;
}
twoPow; // 1024
```

### `while` [#while-loop]
Expand Down

0 comments on commit 9655bac

Please sign in to comment.