The solution is simple, and is based on the fact that Visual Basic supports as many as three different kinds of loops: For, Do, and While. Each kind of loop supports a corresponding Exit keyword (Exit For, Exit Do, and Exit While), thus you can rewrite the code as follows:
Code:
Dim i As Integer = 1
Do While i <= 10
For j As Integer = 1 To 20
If Evaluate(i, j) = 0 Then Exit Do
' Do something here
Next
i += 1
Loop
You can use the same technique when you have up to three nested loops.
Incidentally, you can't adopt this technique in C#, because its break statement doesn't have the same "semantics power" of the Exit keyword in VB.
Bookmarks