How to Program a Loop in VB

Firstly we need to create a file., Now we need to create the Loop., Below that line we need to create something that will loop., Closing the Loop is pretty and simple.

4 Steps 1 min read Easy

Step-by-Step Guide

  1. Step 1: 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:
    Imports System.Console Public Class Loop Shared Sub Main() Remember to close the Class and the Sub at the end of the file. '
  2. Step 2: 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. , Here, a WriteLine() will be used to visually see how the loop works.

    WriteLine("Looping...") 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. '

    We just need to tell the compiler to replay the loop until it has looped 10 times.

    Next X Remember:
    If you call your For Loop 'Loopy' then the Next X should be changed to Next Loopy.
  3. Step 3: Below that line we need to create something that will loop.

  4. Step 4: Closing the Loop is pretty and simple.

Detailed Guide

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:
Imports System.Console Public Class Loop Shared Sub Main() Remember to close the Class and the Sub at the end of the file. '

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. , Here, a WriteLine() will be used to visually see how the loop works.

WriteLine("Looping...") 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. '

We just need to tell the compiler to replay the loop until it has looped 10 times.

Next X Remember:
If you call your For Loop 'Loopy' then the Next X should be changed to Next Loopy.

About the Author

D

Deborah Davis

Dedicated to helping readers learn new skills in practical skills and beyond.

82 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: