EDIT: This is not a question of whether the GoTo instruction can be used.
This is a question about how to handle the center of the O (n ^ 3) algorithm in .NET / IL without using the GoTo instruction. Supporters and fellow travelers of Dijkstra's philosophy, please pay attention before reading this question.
Consider the following code, in which, for most cases, the use of the For o = 0 to nz cycle will run from 3 to 18 million times. The routine takes its place in my code as an argument to call Parallel.For (). Area m , ny and nz is between 10 and 300.
It is manually optimized to eliminate stack and subroutine calls, in other words, for speed. My desire is to avoid compiling IL, which includes the calli or call calli inside the innermost loop.
To interrupt the innermost three loops after running the test, I use the GoTo operator to cancel unnecessary tests.
The question is, is there a way to code this without GoTo? Is there a way to encode this code that the .net JIT compiler will compile for faster code without call or calli codes ending in object code?
Sub SomeLambda(m As Integer, newarray As Short(,,)) For n = 0 To ny For o = 0 To nz If newarray(m, n, o) <> 1 AndAlso newarray(m, n, o) <> -1 Then For m1 = m - 1 To m + 1 For n1 = n - 1 To n + 1 For o1 = o - 1 To o + 1 If SomeCondition = True Then 'the array is not out of bounds ' Dim testVal = newarray(m1, n1, o1) If testVal = -1 Then newarray(m, n, o) = -2 GoTo Exitloopslabel2 End If End If Next Next Next Exitloopslabel2: End If Next Next End Sub