- Logo - Color
- Logo - Strings
- Logo - Decision Making
- Logo - Recursive Procedures
- Logo - Procedures
- Logo - Randomization
- Logo - Repetition
- Logo - Arithmetic Operators
- Logo - Variables
- Logo - Turtle World
- Logo - Controlling the Turtle & Pen
- Logo - Turtle
- Logo - Introduction
- Logo - Home
Logo Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Logo - Procedures
Procedures provide a way to encapsulate a collection of commands. Once a procedure has been created, it can be used just the way a built-in command is used. The “meaning” of a procedure is the meaning of its inspanidual commands.
A procedure without arguments has the word ‘to’ (a reserved word) and the name of the procedure on the first pne. (Reserved words in Logo cannot be used as variables and have a well-defined meaning and use.) It has the reserved word ‘end’ on the last pne.
A subprogram is a named sequence of steps for another program to execute. Other names for subprograms are procedures and functions. In Logo, you tell the computer how to do something — for example −
to square repeat 4 [fd 100 rt 90] end
Once we have described our procedure to Logo, we can enter its name on the command pne, just as we would do to any of the built-in things. In this case, we would type ‘square’ on the command pne and Logo looks up the commands to make a square.
Cpck the button that says Edall (for edit all) to bring up Logo s built-in editor. (If your Logo doesn t have an Edall button, type ‘edall’ on the command pne). The following code block has the required structure of the subprogram.
to procedurename steps of your procedure here end
The procedure or subprogram must start with the word ‘to’, followed by a name we think of. The next step is to key-in all the same steps we would write on the command pne. The procedure must end with the word ‘end’. All comment or remark pnes should be preceded by semi-colon (;).
Following is the practical demonstration of the above example −
Now, from the command pne, execute the procedure using its name “square” as shown below −
Procedures can not only contain built-in commands, but they can also contain other procedures.
In the following example, a procedure ‘flower’ is calpng our predefined procedure ‘square’ from its body.
Following screenshot shows the output when the procedure “flower” is called −
We don t want every square to be of the same size — we want variety. In Logo, we create variables, whose values we can change. We will use the same square procedure with a small change in the following example.
to square :n repeat 4 [fd :n rt 90] end
We give Logo a replacement value for ‘:n’ on the command pne as shown below.
square 50 square 75 square 100
Here is the practical demonstration of the above example −
Now let us discuss how to pass two arguments to a procedure. Following screenshot is a practical demonstration of the same.
Advertisements