Microsoft Small Basic

How to create Loops. How to create Loops. How To create Loops

Modified: 2009/11/28 15:38 by 75.208.65.145 - Uncategorized
Sometimes we need to do something a couple of times

'do the following 3 times
   'move the tortoise 50 pixels
   'turn the tortoise 120 degrees
'repeat

This could be translated with some easy cut & pasting
Tortise.Move(50)
Tortise.Turn(120)


Tortise.Move(50)
Tortise.Turn(120)


Tortise.Move(50)
Tortise.Turn(120)

But this quickly becomes tiresome. A better approach is to use the For Loop
For i = 1 to 3
   Tortise.Move(50)
   Tortise.Turn(120)
EndFor

Notice that it seems to more closely follow the english.
'Do the following 6 times 

translates to

 For i = 1 to 6 

and

 'Repeat 

becomes

 EndFor 

ScrewTurn Wiki version 2.0.35. Some of the icons created by FamFamFam.