next up previous contents index
Next: A loop with foreach Up: Loops: Previous: A loop with for   Contents   Index


A loop with while

This is the syntax for while:
while list_to_evaluate list_of_commands
list_to_evaluate is a list containing an instruction set which can be evaluated as a boolean. list_of_commands is a list containing the commands to execute. The LOGO interpreter will continue implementing the list_of_commands so long as the list_to_evaluate is returned as true.
Eg:
while ["true] [rt 1]                    # The turtle will turn around

# An example which allows us to spell the alphabet in reverse

make "list "abcdefghijklmnopqrstuvwxyz
while [not empty? :list] [pr last :list make "list butlast :list]


Loïc 2008-06-08