Tutorial by Examples

For...Next loop is used for repeating the same action for a finite number of times. The statements inside the following loop will be executed 11 times. The first time, i will have the value 0, the second time it will have the value 1, the last time it will have the value 10. For i As Integer = 0 To...
You can use a For Each...Next loop to iterate through any IEnumerable type. This includes arrays, lists, and anything else that may be of type IEnumerable or returns an IEnumerable. An example of looping through a DataTable's Rows property would look like this: For Each row As DataRow In DataTable...
A While loop starts by evaluating a condition. If it is true, the body of the loop is executed. After the body of the loop is executed, the While condition is evaluated again to determine whether to re-execute the body. Dim iteration As Integer = 1 While iteration <= 10 Console.Writeline(ite...
Use Do...Loop to repeat a block of statements While or Until a condition is true, checking the condition either at the beginning or at the end of the loop. Dim x As Integer = 0 Do Console.Write(x & " ") x += 1 Loop While x < 10 or Dim x As Integer = 0 Do While x &l...
Any loop may be terminated or continued early at any point by using the Exit or Continue statements. Exiting You can stop any loop by exiting early. To do this, you can use the keyword Exit along with the name of the loop. LoopExit StatementForExit ForFor EachExit ForDo WhileExit DoWhileExit Whil...
A nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop...

Page 1 of 1