Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Latest commit

927a5de · May 4, 2025

History

History
45 lines (32 loc) · 685 Bytes

language_for.mdx

File metadata and controls

45 lines (32 loc) · 685 Bytes
id keywords name summary category
for
for
loop
for loop
This is the `for` loop.
languageconstructs

ReScript supports for loops.

For loops can iterate from a starting value up to (and including) the ending value via the to keyword, or in the opposite direction via the downto keyword.

Example

<CodeTab labels={["ReScript", "JS Output"]}>

// Using `to`
for x in 1 to 3 {
  Console.log(x)
}

// Using `downto`
for y in 3 downto 1 {
  Console.log(y)
}
for(var x = 1; x <= 3; ++x){
  console.log(x);
}

for(var y = 3; y >= 1; --y){
  console.log(y);
}

References