Android Question Exit Select?

Emmy

Member
Licensed User
Longtime User
This pseudo code:


Dim Index As Long

For Index = 1 To 100
If Index = > 30 Then
Select Case Index
Case 34
Case 56
Exit Select
Case 89
Case Else
' more code goes here.
End Select
End If
Next

is giving me this error:

Parsing code. Error
Error parsing program.
Error description: Missing Keyword: end select
Occurred on line: 44
End If


But i dont know.

Where can i find a list of supported statements? can i exit from a select block?

Thanks.
 

Mahares

Expert
Licensed User
Longtime User
1. If Index = > 30 Then should be: If Index > = 30 Then
2. Exit Select should be: Exit
3. I am not sure the code is very sound though. I do not think you need the If line and the end if line code. Also, I think Return should replace Exit.
 
Upvote 0

Emmy

Member
Licensed User
Longtime User
You are right. The source code is nonsense. Thats why i called if pseudo-code. :)
The = > compiles fine, anyway. Its the EXIT SELECT what gives it trouble.

I am just trying to understand how this flavor of basic works. So, if i want to
exit from an IF statement from within a SELECT CASE block, how would i go?
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
Depends on exactly what you want to do when Index = 56. If you simply want to exit the Select/Case block and go to the line immediately after End Select, then just do nothing there.
B4X:
    Dim Index As Long 

    For Index = 1 To 100
        If Index >= 30 Then
            Select Case Index
            Case 34
                Log(Index & " Case 34 ")
            Case 56
                'Do Nothing
            Case 89
                Log(Index & " Case 89")
            Case Else
                Log(Index & " Case Else")
            End Select
        End If
    Next
 
Upvote 0

Emmy

Member
Licensed User
Longtime User
I guess i didnt explain very well, the point was not to make THAT code work. It is only pseudo-code. The point was to know how to exit from a SELECT block but continue inside the IF and FOR/NEXT blocks. Why, because there might be more code after the EXIT SELECT. Let me explain better... How would i go doing the following?

B4X:
For Index = 1 To 100
    If Index = > 30 Then
        Select Case Index
            Case 34
            Case 56
                ...some code here
                IF (condition) THEN Exit Select  ' JUMP FROM HERE |
                ...more code here...                             '|  
            Case 89                                              '|                    
            Case Else                                            '| 
            ' more code goes here.                               '|
        End Select                                               '|
                    '<---to here ?--------------------------------
        MORE STATEMENTS                      
    End If
Next

PLease bear with me, im just trying to grasp the basics.
 
Last edited:
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Hi Emmy .. here's my take on this ..
I don't think its a case of setting an argument to Exit the Select Case as that will occur anyway if the .. If / End If condition is NOT met
B4X:
For Index = 1 To 100
  If Index = > 30 Then   'example Index = 56
    Select Case Index
      Case 34
      Case 56
        '...some code here

        If (condition) Then     '** if NOT condition code will naturally jump to End Select
          'do some code .....
        End If

      Case 89
      Case Else
        ' more code goes here.
     End Select

     'Index = 30 to 100
     'MORE STATEMENTS are now processed.
  End If
Next

Edit : Just to clarify ... in your last post , why would you set a condition to exit the Select Case..
It will occur anyway after the Case code has been processed.

B4X:
Case 56
  ...some code here

  'all done .. Jumping to End Select !

Case 89
Case Else
 
Last edited:
Upvote 0

Emmy

Member
Licensed User
Longtime User
...Just to clarify ... in your last post , why would you set a condition to exit the Select Case..

It was only to explain that i wanted to exit the select, but remain inside the IF statement. The code does nothing. :)

Thanks. :)
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I understand that the code does nothing ..
You WILL exit the Select Case Statement anyway after your 'Case' code is executed .. And remain in the IF statement. :)
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
I think what mangojack is saying is, instead of setting a condition for exiting the Select/Case, set the condition for executing the code.
So if you want a part of Case 56 to execute unless j = 10, then instead of doing this:
B4X:
    Case 56
        '...some code
        If j = 10 Then Exit Select
        '...Some code
do this
B4X:
    Case 56
        '...some code
        If j <> 10 Then
            '...Some code
        End If
 
Upvote 0

Emmy

Member
Licensed User
Longtime User
Yup, thats what i would do. Thanks James and mangojack.

I am used to having at hand commands like EXIT SELECT, EXIT LOOP, etc.

Having a list of supported commands would help a lot.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Upvote 0

Emmy

Member
Licensed User
Longtime User
Thanks moster. I searched in several places intil i gave up. I was kind of expecting a local file that i can use offline. Not all my work computer has internet.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
or just download the Beginner's Guide and the User Guide written by Klaus and save them somewhere on your desktop (no need to be online). The guides are PDF-files and in addition you get lots of sample projects.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I was kind of expecting a local file that i can use offline.
I had written a KeyWords_Views.pdf booklet which was shipped with the Beginner's Guide but I left it out because the maintaining.
If you send me your e-mail address in a private message I could send you the last version.
 
Upvote 0
Top