This process of sequential operation is called program flow. Once Logo begins to execute a procedure, the control of the computer passes from the keyboard to the procedure. Logo provides commands that allow you to control the flow of the computer's operation from within Logo procedures. You can use IF and related primitive to test conditions in the Logo environment and pass control to one procedure or another depending on the condition being met. You can let the user determine how the program is to proceed by considering input from the keyboard to determine which procedure to call next. Your Logo program can examine information in disk files and operate in various manners according to what is encountered. The ability to control he flow and timing of your computer is a powerful aspect of Logo.
The following primitives and system names allow you to control the flow of your procedures:
The recursive SQUARE procedure above continued operation endlessly until it was interrupted with certain combinations of keys that tell the computer to stop whatever it was doing (Control-G or the Stop button). It might be useful to have the procedure stop and return control to the user after it has drawn the largest square that will fit on the screen. The following example shows a SQUARE procedure that will stop after it has drawn a square of size 200:
? TO SQUARE :SIDE
> IF :SIDE > 200 THEN STOP
> REPEAT 4 [FD :SIDE RT 90]
? SQUARE 10SQUARE draws square as it did before, but each time it calls itself it examines the value of :SIDE to see if it is greater than 200. When the value of :SIDE exceed 200 the procedures stops and returns control to the user, as indicated by the question mark (?) prompt indicating that Logo is waiting for further instruction.