From 42f59af812710c27b053acfd038eec0561f70f7b Mon Sep 17 00:00:00 2001 From: Leedehai <18319900+Leedehai@users.noreply.github.com> Date: Fri, 2 Feb 2024 03:51:44 -0500 Subject: Allow for-loop to iterate over bytes (#3317) --- docs/reference/scripting.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'docs') 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. -- cgit v1.2.3