assignment: loops

 

For ... next loop

One thing at which computers are perhaps better than people is repetitive tasks - doing something over, and over, and over.

Make a copy of your simple drawing to work on, or start with a blank project. Put this in the "paint" event of your canvas.

Dim i as integer
for i = 1 to 100
   g.drawline (i * 5, 200, i* 5, 220) 
next i 

What does it do? What happens if you change the '5's to '10's?

Random

Try this one:

Dim i as integer
for i = 1 to 100
   g.drawline(rnd * 500, rnd * 500, rnd * 500, rnd * 500)
next i

rnd gives a random number between zero and one. If you multiply it by 500 you get a random number between 0 and 499.

Assignment

Make an interesting drawing using both loops and random. At least four loops should use the index (i in my examples) in a calculation to make something interesting. Your project should have:

At least 6 loops

At least four loops that use the index in a calculation

Extra

Investigate the "Timer" control. To use a timer, drag a timer into your window. Set its "mode" property to 2. In the action event of the timer, put the code you want to execute. You can make an animation using the timer.