While True
Start:
Continue While
GoTo(Start)
End While
NOTE: I know GoTo will never get reach in this example. I am just wondering if there is any computational difference between using GoTo (X) and (Exit / Continue) statements? I tend to like to use GoTo statements even where Continue or Exit would suffice. Is this bad style? I don’t see GoTo in other programmers code very often.
EDIT: As people kindly pointed out the GoTo would not evaluate the condition on a conditional while loop. Which leads me to ask would the following two pieces of code compile down to the exact same CLR code:
Dim x as Integer = 0
While x < 5
Continue
End While
And
Dim x As Integer = 0
JumpPoint:
If x < 5 Then
GoTo JumpPoint
End If
There is one little difference: For
Continue, the condition of the while loop is reevaluated,GoTosimple continues execution from the Start label without looking at the while condition.Would be the same as
in terms of “what happens”. But as soon as a condition is introduced, the
GoTowouldn’t do the same.For your updated question: Yes, there is one difference, again. The first statement includes the
Continuewhich does (basically) the same as theGoTo. But what is not included in your example is a case where theContinueorGoTois not called because of any operation which took place in between. IfContinueis skipped, theEnd Whilewill just loop over to the nextWhileevaluation and run.