Programming & Scripting Tutorials

Visual Basic: While Loops





While loops are loops which do things while a certain condition is true. They are extremely useful in visual basic as a lot of the time you will need to repeat an action a certain number of times.

To demonstrate how while loops work I suggest you read through this piece of code which makes 20 pop-ups which say the number your on, on each one:

Dim int1 As Integer

While int1 < 20
      MsgBox(int1)
      int1 += 1
End While

While loops are a type of loop that are often used in games actually as in games you want things to happen for a certain amount of time; or until a variable changes value.

Also just to clarify, some people have been confused on the last few lessons; and I just wanted to make sure you guys understand; Basically the past few lessons (on different operators and statements) have been things that you can put in different object methods, like button1_click for example. Many lessons after this may feature code like this so if you don't really know where to put it, just experiment; usually it will be inside an object method.

This Visual Basic tutorial was written by


Back to Visual Basic

Advertisement: