For Next Loop In VB.NET
How to use For Next Loop?
Explanation
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.
Syntax:
For counter = start To end [Step]
[Statement]
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.
Example:
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
Description:
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.