For Next Loops in Visual Basic 6.0

A For Next Loop lets you execute a specific group of program statements a  set of number times in an event procedure. This is useful if you are performing several related calculations, working with elements on screen ot processing several pieces for user inputs.

A For Next Loop is just a shortcut of writing a long list of statements. Because each group of statements in such a list would do essentially the same thing, VB lets you define just one group of statements and request that it would be executed as many times as you want.

In a For Next Loop, start and end determine how long the loop runs

Check the syntax below:


for your_variable = start To end
     code block
     or
     statements to be repeated
Next your_variable

Example:
The following For Next Loop sounds four beeps in rapid succession from the computer's speakers:

For x =  1 To 4
     Beep
Next x

so the output of that would be:

Beep
Beep
Beep
Beep



Based from the book Step by Step Microsoft Visual Basic

No comments:

Post a Comment

Extended Search

Custom Search
Hello World