.while
The .while
directive takes two inputs: a condition and a loop body and does the following:
- Check to see if the condition is true
- If it is, evaluate the loop body and go to step 1
The results of each iteration are concatenated together beneath a Content node:
Example -- Sanitising user input
When using the .readline
directive which reads a single line from the standard input, some sanitisation may be needed on a user’s input.
The following will ask the user for an input until they enter something which isn’t empty
.echo: Please input a number
!x <- .readline
.while{.streq{}: !x}:
.warn: User didn't enter anything
!x <-- .readline