github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/while.md (about) 1 # `while` 2 3 > Loop until condition false 4 5 ## Description 6 7 `while` loops until loops until **condition** is false. 8 9 Normally the **conditional** and executed code block are 2 separate parameters 10 however you can call `while` with just 1 parameter where the code block acts 11 as both the conditional and the code to be ran. 12 13 ## Usage 14 15 Until true 16 17 ``` 18 while { condition } { code-block } -> <stdout> 19 ``` 20 21 ``` 22 while { code-block } -> <stdout> 23 ``` 24 25 Until false 26 27 ``` 28 !while { condition } { code-block } -> <stdout> 29 ``` 30 31 ``` 32 !while { code-block } -> <stdout> 33 ``` 34 35 ## Examples 36 37 `while` **$i** is less then **5** 38 39 ``` 40 » i=0; while { $i<5 } { i=$i+1; out $i } 41 1 42 2 43 3 44 4 45 5 46 ``` 47 48 ``` 49 » i=0; while { i=$i+1; $i<5; out } 50 true 51 true 52 true 53 true 54 false 55 ``` 56 57 `while` **$i** is _NOT_ greater than or equal to **5** 58 59 ``` 60 » i=0; !while { $i >= 5 } { $i += 1; out $i } 61 1 62 2 63 3 64 4 65 5 66 ``` 67 68 ## Detail 69 70 ### Meta values 71 72 Meta values are a JSON object stored as the variable `$.`. The meta variable 73 will get overwritten by any other block which invokes meta values. So if you 74 wish to persist meta values across blocks you will need to reassign `$.`, eg 75 76 ``` 77 %[1..3] -> foreach { 78 meta_parent = $. 79 %[7..9] -> foreach { 80 out "$(meta_parent.i): $.i" 81 } 82 } 83 ``` 84 85 The following meta values are defined: 86 87 * `i`: iteration number 88 89 ## Synonyms 90 91 * `while` 92 * `!while` 93 94 95 ## See Also 96 97 * [`err`](../commands/err.md): 98 Print a line to the STDERR 99 * [`for`](../commands/for.md): 100 A more familiar iteration loop to existing developers 101 * [`foreach`](../commands/foreach.md): 102 Iterate through an array 103 * [`formap`](../commands/formap.md): 104 Iterate through a map or other collection of data 105 * [`global`](../commands/global.md): 106 Define a global variable and set it's value 107 * [`let`](../commands/let.md): 108 Evaluate a mathematical function and assign to variable (deprecated) 109 * [`out`](../commands/out.md): 110 Print a string to the STDOUT with a trailing new line character 111 * [`set`](../commands/set.md): 112 Define a local variable and set it's value 113 114 <hr/> 115 116 This document was generated from [builtins/core/structs/while_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/structs/while_doc.yaml).