Here we are going to draw a group of vertical lines across the (x, y) graph
using a loop. We will start at the left where x = -9 and draw a vertical line
there. Then we will move over one unit to the right where x = -8 and draw
another vertical line. We will continue looping till we get to x = 9. At that
position we will draw a vertical line and quit the loop.
Running the example program
Be sure to note the following:
Nothing happens in the before or after loop code.
The program does not animate. Note the stop command
at the end of the loop code.
The section of the x-axis over which the design is drawn is bounded
by x1 and x2.
The top and bottom line segment endpoint coordinates are given by y1
A for loop draws the design.
The for loop runs the values for the variable
from the left bound to the right bound one unit at a time.
It does this in the control section of the loop.
A vertical line segment has the same x-coordinate for both of its endpoints.
As the for loop runs this x-coordinate is held by the variable
During each cycle of the for loop a vertical line
is drawn at the new x-coordinate given by the variable x.
The example program
0ptions Angle measurement: DegreesRadians
Go on input
Try drawing over a different extent of the x-axis. Do this by changing the
values for x1 and x2. For example, this would
draw the line segments only on the right
side of the graph:
x1 = 1;
x2 = 9;
Try drawing shorter line segments by changing y1 and
y2, perhaps like this:
y1 = -2;
y2 = 2;
Make the line segments closer together or farther apart. This would be done
by changing the control statement of the for loop. Here is the
start of a for loop that would make many more line segments and
place the them much closer to one another: