I've noticed an "awkward" issue in VB.... how to escape from things like nested loops or nested IFs, where the standard Exit Loop, Exit For, or Exit If simply starts a new iteration.
For example, assume we have a 3-dimensional array (TheArray) that we want to brute-force test to see if it contains a "true" value. The easiest way would probably be this:
For X = 0 To 50
For Y = 0 To 50
For Z = 0 To 50
If TheArray(X, Y, Z) = True Then GoTo ExitLoops
Next
Next
Next
ExitLoops:
'Do something else here
But I've always been taught to avoid GOTO statements.... With that in mind, I could do this:
Dim Exiting As Boolean = False
For X = 0 To 50
For Y = 0 To 50
For Z = 0 To 50
If TheArray(X, Y, Z) = True Then Exiting = True : Exit For
Next
If Exiting Then Exit For
Next
If Exiting Then Exit For
Next
'Do what you will here
but that makes the code longer, harder to read, and its a pain to have to explicitly exit all the loops, especially as the nest gets deeper...
So we could do this:
Do
For X = 0 To 50
For Y = 0 To 50
For Z = 0 To 50
If TheArray(X, Y, Z) = True Then Exit Do
Next
Next
Next
Loop While 1 <> 1
'Do something here
But that also gets confusing, as the Do really does nothing, not to mention it's not made to act like a container.
So shouldn't we have something like a "Section" block? Something with syntax like this:
Section <Name>
'Statements go here
End Section
and you can exit the section with
Exit <SectionName>
So, in our example, it then becomes:
Section LoopingPart
For X = 0 To 50
For Y = 0 To 50
For Z = 0 To 50
If TheArray(X, Y, Z) = True Then Exit LoopingPart
Next
Next
Next
End Section
'Do something here
Finally, a method that uses a proper block, is easy to read, and easy to code!
But as far as I know, nothing of the sort exists in VB. Am I right?