From 927a5de0169639bc0bc0331e300639ccbab59bb9 Mon Sep 17 00:00:00 2001
From: Gabriel Nordeborn <gabbe.nord@gmail.com>
Date: Sun, 4 May 2025 23:33:06 +0200
Subject: [PATCH] add for and while loops to the syntax widget

---
 misc_docs/syntax/language_for.mdx   | 45 ++++++++++++++++++++++++++
 misc_docs/syntax/language_while.mdx | 50 +++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 misc_docs/syntax/language_for.mdx
 create mode 100644 misc_docs/syntax/language_while.mdx

diff --git a/misc_docs/syntax/language_for.mdx b/misc_docs/syntax/language_for.mdx
new file mode 100644
index 000000000..96908a4f4
--- /dev/null
+++ b/misc_docs/syntax/language_for.mdx
@@ -0,0 +1,45 @@
+---
+id: "for"
+keywords: ["for", "loop"]
+name: "for loop"
+summary: "This is the `for` loop."
+category: "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"]}>
+
+```res
+// Using `to`
+for x in 1 to 3 {
+  Console.log(x)
+}
+
+// Using `downto`
+for y in 3 downto 1 {
+  Console.log(y)
+}
+```
+
+```js
+for(var x = 1; x <= 3; ++x){
+  console.log(x);
+}
+
+for(var y = 3; y >= 1; --y){
+  console.log(y);
+}
+```
+
+</CodeTab>
+
+
+### References
+
+* [For Loops](control-flow.md#for-loops)
+
diff --git a/misc_docs/syntax/language_while.mdx b/misc_docs/syntax/language_while.mdx
new file mode 100644
index 000000000..87f9b3b4b
--- /dev/null
+++ b/misc_docs/syntax/language_while.mdx
@@ -0,0 +1,50 @@
+---
+id: "while"
+keywords: ["while", "loop"]
+name: "while loop"
+summary: "This is the `while` loop."
+category: "languageconstructs"
+---
+
+ReScript supports `while` loops. While loops execute its body code block while its condition is true. 
+
+ReScript does not have the `break` keyword, but you can easily break out of a while loop by using a mutable binding.
+
+### Example
+
+<CodeTab labels={["ReScript", "JS Output"]}>
+
+```res
+let break = ref(false)
+
+while !break.contents {
+  if Math.random() > 0.3 {
+    break := true
+  } else {
+    Console.log("Still running")
+  }
+}
+
+```
+
+```js
+let $$break = {
+  contents: false
+};
+
+while (!$$break.contents) {
+  if (Math.random() > 0.3) {
+    $$break.contents = true;
+  } else {
+    console.log("Still running");
+  }
+};
+```
+
+</CodeTab>
+
+
+### References
+
+* [While Loops](control-flow.md#while-loops)
+