Android Question select case - every case tested even if a match is found early?

Dave O

Well-Known Member
Licensed User
Longtime User
I've been using the SELECT TRUE construct to simplify some conditional logic, like this:

B4X:
sub evaluateHand as short
    Select True
       Case isRoyalFlush
           Return 10
       Case isQuads
           Return 10
       Case isStraightFlush
           Return 10
       Case isFullHouse
           Return 9
   End Select
end sub

I had been assuming that if a case returns TRUE (e.g. isRoyalFlush), then the SELECT statement does that block (e.g. Return 10), then exits the SELECT statement (i.e. just like an IF statement would skip the ELSE logic).

However, it seems that SELECT tests every case, even if it gets a match early on. Is this true, and if so, is this the proper behaviour? If I have several cases that match, would all of those blocks get executed? Even if I use a RETURN as above?

(In the example above, a royal flush is also a straight flush. Ideally, I only want 1 case returned.)

If so, that's an important difference from using the alternative IF/ELSE/ELSE/etc construct.
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi,

I figure that the problem is in use of "True" in the select.

Just try

B4X:
    Select Result
        Case IsRoyalFlush
            Return 10
        Case IsQuads
            Return 10
        Case IsStraightFlush
            Return 10
        Case IsFullHouse
            Return 9
        Case Else
            Return 0
    End Select

Regards,

Edgar
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…