Learning Objectives

Video Lessons

Reference

Testing for Understanding

  1. TFU #1
  2. TFU #2
  3. TFU #3
  4. TFU #4
  5. TFU #5

Related Links

Logo How-Tos

Logo in your browser

Logo Software

Logo Organizations

Logo Forums

The work on this shelf is powered by you and

MicroWorlds Web Player is officially supported under Internet Explorer or Netscape 4 or higher

Subprocedures

In Procedures, we mentioned four ways that a procedure can be used:

  • in the Command Center
  • in the Rules tab of a turtle's backpack
  • in a button
  • in the definition of another procedure
This includes procedures you have written yourself as well as primitive procedures. In this section, we will talk more about using a procedure you already defined inside the definition of another procedure you are writing.

Suppose that you have defined the square procedure:

to square
fd 50 rt 90
fd 50 rt 90
fd 50 rt 90
fd 50 rt 90
end

and the triangle procedure:

to triangle
fd 50 rt 120
fd 50 rt 120
fd 50 rt 120
end

(The text below is from MicroWorlds EX > Programming > Programming Fundamentals > Writing Procedures)

You can now use these procedures to define the house procedure:

to house
square
forward 100
right 30
triangle
end

When you run house, you are running the procedures square and triangle indirectly. House runs them for you. Here is a model of what is happening:

MicroWorlds goes through each instruction in the house procedure. When it sees the instruction for , it looks for the definition of square and runs the body of that procedure. In the case of square, the body is fd 50 rt 90 fd 50 rt 90 fd 50 rt 90 fd 50 rt 90.
Then it goes on to forward and right (MicroWorlds knows that these are primitives).
When it reaches triangle, it looks for the definition of triangle and runs that procedure.
Then MicroWorlds goes on to the next line of house which is end. Now house is finished.

Square and triangle are subprocedures of house. House is the superprocedure of square and triangle.

About the Center for Talent Development

Center for Talent Development (CTD), housed at Northwestern University's School of Education and Social Policy, is an accredited learning center and research facility that identifies, educates and supports gifted students and their families and serves as a leader in gifted education. Learn more about the Center for Talent Development.

Leone Learning Systems, Inc. (LLS) is a North Shore company that provides online courses for kids anywhere and local teaching and tutoring services for students in Chicago and the Northern Suburbs of Chicagoland. LLS also provides a free geometry software package for children age 6 and up, and free resources for teachers and parents. This site includes information about classes taught, availability for tutoring, learning activities for kids, lesson plans, and ongoing software and curriculum research and development efforts.