The while loop is a control statement that allows code to be executed repeatedly until a given Boolean condition is met. It’s a lot easier to see it than to read about it. If you understand how while loops works then you should easily understand the other loops available in Visual Basic and other various programming languages.

1. Open a Microsoft Visual Studio.

2. Click File > New > Web Site.

3. Choose Visual Basic for installed templates and select ASP.NET Empty Web Site.

4. Right click on the project solution. Click Add New Item.

5. Choose Visual Basic for installed templates and select Web Form. Keep the file name as Default.aspx.

6. You will see code already in Default.aspx. There is a set of div tags. Inside, enter a new set of p tags to create a new paragraph.

We chose Server Intellect for its cloud hosting, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

Code Block
Default.aspx
Insert p tags to create a new paragraph.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>
    
    </p>
    </div>
    </form>
</body>
</html>
In the toolbox, we will need to grab a label and button.

7. Go to toolbox, click and drag a Button tool under the Label tool we just created. Change the Text of Button to “Use While Loop”

8. Go to toolbox, click and drag a Label tool inside the paragraph tag we created. Delete the Text in Label.

Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.

Code Block
Default.aspx
Delete the text in Label  and change the text of Button.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>
        <asp:Button ID="Button1" runat="server" Text="Use While Loop"/>
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </p>
    </div>
    </form>
</body>
</html>

10. Click on Default.aspx and switch to Design view.

11. You will see an empty Label and a Button with the words “Use While Loop”. Double click on the button.

This will take you to Default.aspx.vb. This is where we enter coding specifically for Visual Basic.

12. You should see a method called Button1_Click.. Inside this method we will enter While Loop that has a number start at 0 and end until it is less than or equals to 10.

We stand behind Server Intellect and their support team. They offer dedicated servers, and they are now offering cloud hosting

Code Block
Default.aspx.vb
While loop that repeats until the count is less than or equal to 10.
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgsHandles Button1.Click
        Dim count = 0

        While (count <= 10)
            count = count + 1
        End While Label1.Text = count

    End Sub
End Class
13. Run the application. You will see a blank page with a button with the text Use While Loop. Click it and it will perform the while loop we coded into the Button1_Click method. The output will be 10.

The while loop is an important and simple function for keeping track of when an action should take place. Like I mentioned earlier, if you understand how to use the while loop, learning the other loops in visual basic and other various programming languages should be a breeze.

WebSite18.zip