wonder Expert Licensed User Longtime User Sep 26, 2016 #1 Which one is correct? Code: Copy 'Example A: Dim n = 0 As Int Select n Case 0 n = 1 Exit Case 1 n = 100 Exit End Select or Code: Copy 'Example B: Dim n = 0 As Int Select n Case 0 n = 1 Case 1 n = 100 End Select
Which one is correct? Code: Copy 'Example A: Dim n = 0 As Int Select n Case 0 n = 1 Exit Case 1 n = 100 Exit End Select or Code: Copy 'Example B: Dim n = 0 As Int Select n Case 0 n = 1 Case 1 n = 100 End Select
S sorex Expert Licensed User Longtime User Sep 26, 2016 #4 it already implements a break. some languages (PHP for example) require that you set it yourself tho. Upvote 0
it already implements a break. some languages (PHP for example) require that you set it yourself tho.
LucaMs Expert Licensed User Longtime User Sep 26, 2016 #5 I'm almost sure that you can even add a break (which is not needed) using Continue (it works on loops). Damn, now I have to try Upvote 0
I'm almost sure that you can even add a break (which is not needed) using Continue (it works on loops). Damn, now I have to try
LucaMs Expert Licensed User Longtime User Sep 26, 2016 #6 LucaMs said: I'm almost sure that you can even add a break (which is not needed) using Continue (it works on loops). Damn, now I have to try Click to expand... Tried: it's False , Continue cannot be used. Upvote 0
LucaMs said: I'm almost sure that you can even add a break (which is not needed) using Continue (it works on loops). Damn, now I have to try Click to expand... Tried: it's False , Continue cannot be used.
tigrot Well-Known Member Licensed User Longtime User Sep 26, 2016 #7 Exit case is not a Basic statement. In C and related dialects you need to Exit since every subsequent statement will be executed also if it"s not the case... In Basic every single case is tested. Upvote 0
Exit case is not a Basic statement. In C and related dialects you need to Exit since every subsequent statement will be executed also if it"s not the case... In Basic every single case is tested.
LucaMs Expert Licensed User Longtime User Sep 27, 2016 #8 With VB.Net you can exit from a single case, using Exit Select: Code: Copy 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
With VB.Net you can exit from a single case, using Exit Select: Code: Copy 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