diff options
| author | Leedehai <18319900+Leedehai@users.noreply.github.com> | 2024-02-02 03:51:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-02 08:51:44 +0000 |
| commit | 42f59af812710c27b053acfd038eec0561f70f7b (patch) | |
| tree | c8bb69bd9a28d91496facdc498f63e13faaafd94 /docs/reference/scripting.md | |
| parent | 464a15bdca3ea3a54adc6410ba679597d7ca421b (diff) | |
Allow for-loop to iterate over bytes (#3317)
Diffstat (limited to 'docs/reference/scripting.md')
| -rw-r--r-- | docs/reference/scripting.md | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/docs/reference/scripting.md b/docs/reference/scripting.md index ee9478bb..6e64cebb 100644 --- a/docs/reference/scripting.md +++ b/docs/reference/scripting.md @@ -188,13 +188,6 @@ together into one larger array. For loops can iterate over a variety of collections: -- `{for letter in "abc" {..}}` \ - Iterates over the characters of the [string]($str). - (Technically, iterates over the grapheme clusters of the string. Most of the - time, a grapheme cluster is just a single character/codepoint. However, some - constructs like flag emojis that consist of multiple codepoints are still only - one cluster.) - - `{for value in array {..}}` \ Iterates over the items in the [array]($array). The destructuring syntax described in [Let binding]($scripting/#bindings) can also be used here. @@ -203,6 +196,17 @@ For loops can iterate over a variety of collections: Iterates over the key-value pairs of the [dictionary]($dictionary). The pairs can also be destructured by using `{for (key, value) in dict {..}}`. +- `{for letter in "abc" {..}}` \ + Iterates over the characters of the [string]($str). Technically, it iterates + over the grapheme clusters of the string. Most of the time, a grapheme cluster + is just a single codepoint. However, a grapheme cluster could contain multiple + codepoints, like a flag emoji. + +- `{for byte in bytes("😀") {..}}` \ + Iterates over the [bytes]($bytes), which can be converted from a [string]($str) + or [read]($read) from a file without encoding. Each byte value is an + [integer]($int) between `{0}` and `{255}`. + To control the execution of the loop, Typst provides the `{break}` and `{continue}` statements. The former performs an early exit from the loop while the latter skips ahead to the next iteration of the loop. |
