Exit and Continue statements
In VB, the Exit
and Continue
statements are used to modify the flow of execution in loops and conditional statements.
The Exit
statement immediately exits a loop or a Select Case
or Do Select
statement. When the Exit
statement is reached, control passes to the next statement after the loop or the Select Case
or Do
Select
statement.
Here is a VB.NET example that searches for a specific value in a loop and will exit the loop if found:
Dim test_value As Integer = 7 Dim found As Boolean = False For x As Integer = 1 To 20 If x = test_value Then Found = True Exit For End If Next If found Then Console.WriteLine("The search value was found.") End If
The Continue
statement is used to skip to the next loop iteration immediately. When the Continue
statement is executed, the loop...