Glich - v0.3.0 Manual
do Loop Statement
Development v0.3.0 Manual Glich Script Statements do Statement

Statement: do { ... };

A do { statements ... }; statement runs the statements in between until a 'while condition' or 'until condition' sub-statement causes the loop to exit. Currently the maximum number of iterations is fixed at 1000.

If a 'while condition;' sub-statement is encountered and the condition is false, the execution of the script moves to the first statement after the end of the do { ... }; statement. Encountering an 'until condition;' sub-statement breaks out of the loop if the condition is true.

do Statement Format
do { statements ... while bool_expr; statements ... until bool_expr; statements ... };
do Statement
ExampleOutput
let day = @date.g:dmy("1apr2017"); do { write @text."g:wdmy+"(day) nl; until day >= @date.g:dmy("1may2017"); day += 7; }; Saturday 1 April 2017
Saturday 8 April 2017
Saturday 15 April 2017
Saturday 22 April 2017
Saturday 29 April 2017
Saturday 6 May 2017

Statement: do int in range { ... };

A do int in range { statements ... }; statement runs the statements in between for each integer in the given range. The integer variable is set to the current integer in the range for each iteration of the loop.

The statement creates or reuses a local variable with the name given by int. The variable is not scoped and is available after the loop has finished.

do Statement
ExampleOutput
let a = {: 2, 3, 5, 7, 11, 13, 17, 19 }; do i in 0..a@size-1 { write a[(i)] * a[(i)],; }; 4, 9, 25, 49, 121, 169, 289, 361

Use the the keyword in:r to iterate over the range in reverse order.

Statement: do value in object { ... };

A do value in object { statements ... }; statement runs the statements in between for each value in the given object. The value variable is set to the current value in the object for each iteration of the loop.

The statement creates or reuses a local variable with the name given by value. The variable is not scoped and is available after the loop has finished.

do Statement
ExampleOutput
let obj = {: "Example text", 3, 5..7, 11 | 13 }; do val in obj { write val,; }; Example text, 3, 5..7, 11 | 13,

The keyword in:r can also be used with objects to iterate over the values in reverse order.

Development v0.3.0 Manual Glich Script Statements do Statement

Managed by WebPageLayout Validated by HTML Validator (based on Tidy)

9th March 2023