Wednesday, March 5, 2008

How to use Loops of VB?

_____________________________________________

How to use Loops of VB?

_____________________________________________

Pre-test Loops:
While c <>End While

Do Until c = 10
c += 1
Loop

Do While c <>Loop

For c = 2 To 10 Step 2
Console.WriteLine(c)
Next


Post-test Loops:
Do
c += 1
Loop While c <>
Do
c += 1
Loop Until c = 10

' Array or collection looping
Dim names As String() = {"Fred", "Sue", "Barney"}
For Each s As String In names
Console.WriteLine(s)
Next

' Breaking out of loops
Dim i As Integer = 0
While (True)
If (i = 5) Then Exit While
i += 1
End While


' Continue to next iteration
For i = 0 To 4
If i <>Continue For
Console.WriteLine(i) ' Only prints 4
Next

____________________________________________________________________

Note:Applicable for .net also asp.net.
____________________________________________________________________

No comments: