|
Lektion 5: Parameters |
|
©1997/1998 Sebastian Golze, Thomas Hirsch
und
|
[1_First_steps] [2_Turn_left_turn_rigth] [3_With_colors] [4_Procedures] [5_Parameters] [6_Loops] [7_More_parameters] [8_Stars] [9_Upload_and_Download] [10_LOGO_learns_to_write]
Great. If you've made it to this lesson, you've already made your first steps to real programming. In fact, a good computer program does not only tell the computer what to do, but uses as much procedures as possible, to get a small size and a clear structure. If you had an almost infinite list of gos and rights, you would certainly not understand what LOGO is about to do. If you've got some well-named procedures, you'll see on the first view : "Hey - the procedure square draws a square !" But what do you do, when you want to draw several squares of different size. For now, you're not able to tell LOGO "draw a large square", are you ? You can draw a procedure respecting a certain value, a variable. A variable is a number that is able to vary. For example you want to vary the size of the squares that you draw. A procedure that can use any number for the size looks like this:
If you compare this procedure to the former ones, you'll notice the word size.
Right, that's a variable. But how do you tell LOGO to draw this square in a certain size ?
procedure main Every time that LOGO encounters the name of the variable (size) in the procedure, he replaces it by the value after the equality sign (100). Consider now, how to program a rectangle. You will need more than one variable, if you want to change both length and width. The command goto looks like the following goto rectangle length=100,large=50 Separate all variables by commas. Thus you may use as much variables as you want.
You can use your newly created procedure in another procedure house. Just place
a triangle over that rectangle. Please keep the procedure house for the next lesson... |