Home > IB Computer Science 2017 > Recursion in Logo

Recursion in Logo


to factorialI :n
local "x
make "x 1
repeat :n [make "x :x * repcount]
op :x
end

to factorialR :n
ifelse :n = 1 [op 1] [op :n * factorialR :n - 1]
end

to polygonI :sides :length
repeat :sides [fd :length rt 360/:sides]
end

to polygonR :sides :length :count
ifelse :count = 0 [stop] [fd :length rt 360/:sides polygonR :sides :length :count - 1]
end

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s