There are many different types of Loop within VB (Visual Basic) such as a ‘For Loop’, ‘Do Loop’ etc. The Loop we’ll take a loop at is a For Loop. A For Loop is used mainly when the Programmer wants to define how many times the loop will run.
[notice type="support" title="STEP BY STEP" tag="h4"]STEP[/notice]
Firstly we need to create a file. So open up Notepad or any other text editing software. Then Import a Class Library, Create a Public Class and then create a Sub (Method). Like So:
Public Class Loop
Shared Sub Main()
Remember to close the Class and the Sub at the end of the file. ‘
Now we need to create the Loop. Which is a For Loop. Mainly and For loop is used when the programmer wants to define how many times the Loop loops for.
- For X = 1 to 10
This will create a loop that loop 10 times. I’ve called this Loop X.
Below that line we need to create something that will loop. Here, a WriteLine() will be used to visually see how the loop works.
As you can see this line will print ‘Looping…’ to the command window. But with the help of the For Loop it will repeat 10 times. ‘
Closing the Loop is pretty and simple. We just need to tell the compiler to replay the loop until it has looped 10 times.
Remember: If you call your For Loop ‘Loopy’ then the Next X should be changed to Next Loopy.