id | keywords | name | summary | category | ||
---|---|---|---|---|---|---|
for |
|
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.
<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);
}