Blog Advertising - Advertise on blogs with SponsoredReviews.com

How to Program a Loop in VB

| March 11, 2013

for1 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.

 

 

 

 

 

[dividers style="3"]

[notice type="support" title="STEP BY STEP" tag="h4"]STEP[/notice]

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:

  1. Imports System.Console

  2. Public Class Loop

  3. Shared Sub Main()

    • Remember to close the Class and the Sub at the end of the file.

     

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.

  1. For X = 1 to 10

This will create a loop that loop 10 times. I’ve called this Loop X.

STEP 3

Below that line we need to create something that will loop. Here, a WriteLine() will be used to visually see how the loop works.

  1. 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. ‘

STEP 4

Closing the Loop is pretty and simple. We just need to tell the compiler to replay the loop until it has looped 10 times.

  1. Next X

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

 

Tags: , , , , , , , ,

Category: How-To, Programming Tutor

Comments are closed.

Advertiser Here !!!, iPad, Android phones, BlackBerry, iPod, iPhone, Macs and hundreds more!
Blog Advertising - Advertise on blogs with SponsoredReviews.com