Wednesday, April 17, 2013

For Loops in VB.NET

This first type of loop we'll look at is called a For Loop. It is the most common type of loop you'll use when you program. We'll use one to add up our 4 numbers, and then discuss the code. Study the following. In fact, create a new Project. Add a button to your new Form. Double click your new button and type the following code for it:


Dim answer As Integer
Dim startNumber As Integer
answer = 0
For startNumber = 1 To 4
answer = answer + startNumber
Next startNumber
MsgBox answer

Run the program, and see what happens when you click the button. The number 10 should have been displayed in your message box.



No comments:

Post a Comment