Thursday, June 3, 2010

What is tail recursion?

Tail recursion is another way to loop commands. With loop or repeat you give the command and then in brackets specify what is to be repeated. Tail recursion is simpler and a bit of a trick. Here's how:

to count

display 1
wait 5
display 2
wait 5
display 3
wait 5

See? If you put the name of the procedure at the end of the procedure itself, it will just keep looping itself!

No comments: