LOGO Procedures


Here is some Logo code related to recursion.

to factorial :n
 if lessp :n 1 [output 1]         ; Stop with an output of 1 if 0 or invalid.
 output product :n factorial :n-1
end

to square :side
 repeat 4 [forward :side right 90]
end

to down :word
 if emptyp :word [stop]
 print :word
 down butlast :word
end

to tree :size
 if lessp :size 1 [stop]        ; Stop when branches are too small to see
 trunk :size                    ; Trunk
 right 30 tree :size/2          ; Right branch
 left 30 tree :size/2           ; Left branch
end

to trunk :size
 forward :size
end