loop statement
The loop word in VB.NET is divided into: do while loop, for next, for each.
Do While loop
There are three forms of do while loop, which is used in the upper limit of the cycle in advance. Note when using the Do While loop statement because they are uncertainties, so be careful not to cause death cycles.
Do While Loop Example
Public Class Testa
Public Sub New ()
DIM I as Int32
i = 1
Do While i <100 'first judgment
i = 1
Exit do
Loop
i = 1
DO
i = 1
Exit do
LOOP While i <100 'first judgment
While I <100 'Do While i <100
i = 1
Exit while
End while
End Sub
END CLASS
For next
Different than do while loop, for next is a boundary cycle. The FOR statement specifies the loop control variable, the lower limit, the upper limit, and the optional step size.
For Next Example
Public Class Testa
Public Sub New ()
DIM I as Int32
For i = 0 to 100 STEP 2
Next I
End Sub
END CLASS
For ve
FOR Each is also an unmissive cycle, and for Each is traversed for each element in the collection. If you need to traverse an object collection, you should use for Each.
For Each Example
Public Class Testa
Public Sub New ()
Dim Found as boolean = false
DIM MyCollection As New Collection
For Each MyObject As Object in MyCollection
If MyObject.text = "Hello" Then
Found = TRUE
EXIT for
END IF
NEXT
End Sub
END CLASS
Simple statement introduction, we are here, other statements are in the future
VB.NET
Gradually in depth, we will explain one by one.