CDC Community

🔹 Historical Conservation 🔹

User Tools

Site Tools


Repeated Operations: The Iterative -do-

With very little effort we can make a variety of designs out of our unit “halfcirc”. For example:

unit stack calc x⇦256 radius⇦70 do halfcirc,y⇦100,380,70 at 312 write We used an iterative -do-.

The effect of the -do- statement is to set y to 100 and do unit “halfcirc”, then set y to 170 (the starting value of 100 plus an increment of 70) and do halfcirc again, and repeat the process until y reaches the final value of 380. The format of the extremely useful iterative -dostatement is:

do unitname,index⇦start,end,increment

In the above example, the index “y” starts at 100 and goes to 380 in increments of 70. If no increment is specified, an increment of one is assumed. For example, “do halfcirc, radius⇦101,105” will make an arc five dots wide, as in the following figure:

The iterative -do- statement also helps in making animations. The following statements will cause the half-circle to move horizontally across the screen. (See Figures 4-5a and 4-5b.)

unit march at 3120 write Move figure left to right. calc y⇦280 radius⇦75 do anim,x⇦100,350,50 do halfcirc $$ draw final figure at 3220 write All done. * unit anim do halfcirc $$ draw figure catchup $$ wait for it to finish pause 1 $$ pause an additional second mode erase do halfcirc $$ erase the figure mode write

We simply -do- unit “anim” repeatedly for different values of x (the horizontal position of the figure on the screen). Unit “anim” does unit “halfcirc” twice, once to draw and once to erase the figure interrupted by a one-second pause. The -catchup- command insures that a second will elapse from the end of drawing the figure on the screen until the beginning of erasing it.

Now that you have studied -define-, -talc-, and -do-, you have learned the basic techniques of how to tell PLATO what calculations you want performed. We have applied these tools to a variety of display generation problems, and we will later use calculations for controlling sequencing in a lesson and for judging responses. Hopefully, you have gained added insight into the value of a subroutine. Notice how many different ways we have used the single unit “halfcirc”!

Showing the Value of a Variable

tutor/repeated_operations.txt · Last modified: 2022/08/25 13:44 by site_admin