VB.Net - Continue Statement



The Continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. It works somewhat like the Exit statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.

For the For...Next loop, Continue statement causes the conditional test and increment portions of the loop to execute. For the While and Do...While loops, continue statement causes the program control to pass to the conditional tests.

Syntax

The syntax for a Continue statement is as follows −

Continue { Do | For | While }

Flow Diagram

VB.Net continue statement

Example

Module loops
   Sub Main()
      ' local variable definition 
      Dim a As Integer = 10
      Do
         If (a = 15) Then
            ' skip the iteration '
            a = a + 1
            Continue Do
         End If
         Console.WriteLine("value of a: {0}", a)
         a = a + 1
      Loop While (a < 20)
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result −

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
vb.net_loops.htm
Advertisements