Android Question Does SELECT CASE needs the EXIT statement?

wonder

Expert
Licensed User
Longtime User
Which one is correct?
B4X:
'Example A:
Dim n = 0 As Int
Select n
    Case 0
        n = 1
        Exit
      
    Case 1
        n = 100
        Exit

End Select
or
B4X:
'Example B:
Dim n = 0 As Int
Select n
    Case 0
        n = 1      
      
    Case 1
        n = 100      

End Select
 

sorex

Expert
Licensed User
Longtime User
it already implements a break. some languages (PHP for example) require that you set it yourself tho.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
With VB.Net you can exit from a single case, using Exit Select:
B4X:
Dim a As Integer = 3
Dim b As Integer = 30

Select Case a
    Case 3
        Debug.WriteLine("Executed before exit")
        If b = 30 Then
            Exit Select
        End If
        Debug.WriteLine("Executed after exit") ' <--- this line will not be executed
End Select
 
Upvote 0
Top