For Next Loop In VB.NET

How to use For Next Loop?


For Next Loop Statement

For Next Loop Statement executes a set of statements repeatedly in a loop for the given initial, final value range with the specified step by step increment or decrement value.

For counter = start To end [Step]
Next [counter]

In the above syntax the Counter is range of values specified using the Start ,End parameters. The Step specifies step increment or decrement value of the counter for which the statements are executed.

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim j As Integer
j = 0
For i = 1 To 10 Step 1
j = j + 1
MsgBox("Value of j is::" & j)
Next i
End Sub

In the above For Next Loop example the counter value of i is set to be in the range of 1 to 10 and is incremented by 1. The value of j is increased by 1 for 10 times as the loop is repeated.

Visual Basic Tutorial

Ask Questions

Ask Question