Logo. Variables and Procedures.
Using Variables:
To assign a value to a variable using the primitive MSWLogo followed HAZ variable name and value that you want to give the variable. The variable name must be preceded by double quotes ("). The syntax is:
For example:
HAZ "x 20
HAZ" listacolores [RED YELLOW BLUE]
To access the value of a variable must precede the variable name of the colon (:). For example:
SAMPLE : X
HEAD: listacolores
Procedures Definition:
To create a procedure MSWLogo must use the reserved word TO followed by the name of the procedure and its parameters (if any). Then put the definition of the procedure and this will end with the keyword END
.
FOR nombprocedimiento [parameter list]
;
Procedure definition.
. FIN
procedures to create two options:
1. Using the Window Work: to display this window must be written in the input box or primitive FOR name [parameter list] and then press ENTER or the Run button.
then be introduced in this window one by one the statements that the procedure has and will be pressing the OK button. To finish the procedure will be introduced EFINITION the original FIN.
2. Using the Edit Window: To access the Edit window will be used EDITATODO primitive or the File - Edit. In addition to defining procedures in the editing window you can define variables, properties, comments, etc. When you have finished defining the procedure is saved in the menu option File - Save. Let
a couple of examples:
a) The procedure for drawing a square of side 100 would be as follows: FOR cuadrado1
borrapantalla
center advances 100 advances
giraizquierda 90 90 100
giraizquierda
advances 100 advances
giraizquierda 90 100 FIN 90
giraizquierda
b) The procedure for drawing a square of side variable would be the next
:
FOR cuadrado2: size
borrapantalla
center repeat 4 [forward: size giraizquierda 90]
FIN
This procedure, the parameter: size indicates the length of the side of the square you want to draw.
Once defined
procedures, these can be called at any time in a program, or from the execution of primitive writing its name followed by the necessary parameters (if the procedure has them). There might, for example:
cuadrado1
cuadrado2 cuadrado2 100 150
0 comments:
Post a Comment