Turtle Academy just had a system upgrade if you experience any issues. Please try to hard refresh using CTRL + F5.

If the issues continue please contact us.

12. Procedure

Hi ! , if we got here so we already passed a lot , and we have some good knowledge of Logo. Actually we have already learned some procedures in the lesson "The turtle is learning".
Lets start by cleaning the screen
The definition of a basic procedure with no parameters is : to PROCNAME ACTIONS end. When PROCNAME is the name of the procedure and ACTIONS are the commands. In the lesson 'The turtle is learning we have define a procedure called 'dashline' like this . to dashline repeat 5 [setwidth 1 fd 10 setwidth 3 fd 10] end. Here the PROCNAME part is 'dashline' and the ACTIONS part is ' repeat 5 [setwidth 1 fd 10 setwidth 3 fd 10]'.
Define a new procedure called triangle that draws a triangle size 100
Congratulation , you have created a new procedure named triangle , now let's use it. In order to use a procedure with no parameters we will have to call her( write her name ).
please call triangle
We can also create a procedure that expect parameters. the definition will be : to PROCNAME :INPUT1 :INPUT2 ACTIONS end.We can use as many input parameters as we want (when we defined triangle we used 0 input parameters ). We can use the input param in the ACTION.
write the following : to going :fdinput fd :fdinput end
We have defined : to going :fdinput fd :fdinput end. after the to the ":" sign indicate that we have a parameter called fdinput . The ACTIONS part contain fd :fdinput which means that will will go forward as much as the parameter that was given .. confused ?? don't worry , just try to run the following. going 50 , going 100 end etc. Notice .. if you will run the command without a parameter an error will raise because we are expecting exactly 1 parameter now
Run the going procedure with the value 150
At the lesson 'Polygons' we have created a lot of shapes when the only different between them was the number of time we need to repeat and the angle we need to turn . for triangle it was repeat 3 [fd 100 rt 360/3] , for square it was repeat 4[fd 100 rt 360/4]. and in general it was repeat X [fd 100 rt 360/X].
Create a procedure called polygon that expect 1 param name :edges ,and each edge is 100 point size , using turn right.
Now it will be really easy for us to create a lot of cool polygons . we will just have to call the polygon procedure with the parameter.
Create a square
TurtleAcademy learn programming for freeYour browser is not supporting canvasWe recomand you to use Chrome or Firefox browsers