From b71db280756780f6fa14569c8ddbd77b21ed0e72 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 28 Mar 2024 19:46:23 -0500 Subject: [PATCH] Add docs --- md/learn/flow-control/break-continue.md | 0 md/learn/flow-control/loops.md | 22 ++++++++++++++++++---- md/learn/index.yaml | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) delete mode 100644 md/learn/flow-control/break-continue.md diff --git a/md/learn/flow-control/break-continue.md b/md/learn/flow-control/break-continue.md deleted file mode 100644 index e69de29..0000000 diff --git a/md/learn/flow-control/loops.md b/md/learn/flow-control/loops.md index 75e420d..758a017 100644 --- a/md/learn/flow-control/loops.md +++ b/md/learn/flow-control/loops.md @@ -19,7 +19,7 @@ for #(index, number) in numbers.entries() ``` ```thp -val dict = Obj { +val dict = .{ apple: 10, banana: 7, cherries: 3, @@ -58,7 +58,7 @@ while index < colors.size() ## Infinite loop -Basically Rust*'s loop. +Instead of doing `while true {}` use `loop`. ```thp loop @@ -72,8 +72,22 @@ loop } ``` -* Rust is a trademark of the Rust Foundation. THP is not affiliated, -endorsed or supported by the Rust Foundation. + +## Labelled loops + +You can give labels to loops, allowing you to `break` and `continue` in nested loops. + +```thp +:top for i in values_1 +{ + for j in values_2 + { + // ... + break :top + } +} +``` + diff --git a/md/learn/index.yaml b/md/learn/index.yaml index 16111e7..5320cbe 100644 --- a/md/learn/index.yaml +++ b/md/learn/index.yaml @@ -20,6 +20,8 @@ children: - name: Flow control path: flow-control children: + - name: Blocks + path: blocks - name: Conditionals path: conditionals - name: Loops