Select Case evaluation
Posted
#1
(In Topic #1347)
Regular

However, when my code runs, the first Case is matched and processes the contained statements - as expected - but then proceeds straight to End Select instead of dropping down to the next Case! How to I get the code to evaluate each Case in succession as described in the documentation
(/lang/select - Gambas Documentation)?
(The msExists function call should return True in each Case statement, so processing all the code.)
Gambas 3.19.3
Code (gambas)
chrisRoald
Posted
Regular

If you want to test for multiple conditions then Select is not what you want.
AFAICS what you appear to need is just a successive set of If's.
b
p.s. I don't see how you got that idea from the indicated help page, what was unclear?
p.p.s Select Case True is not sensible. It will always be true, as in If True=True then …
Posted
Guru

It Selects the first True condition.
Use If blocks , Select case is like using If and Else if
When it finds a condition to be true it will only run that bit of code and ignore the rest.
Like it Selected it.
Code (gambas)
Posted
Guru

chrisRoald said
Hi, I've coded a function (see below) with a sequence of Cases in a Select Case > End Select statement.
However, when my code runs, the first Case is matched and processes the contained statements - as expected - but then proceeds straight to End Select instead of dropping down to the next Case! How to I get the code to evaluate each Case in succession as described in the documentation
(/lang/select - Gambas Documentation)?
I changed the first line of the wiki page
from this..
Selects an expression to compare, and execute the code enclosed in the corresponding matching CASE statement.
Selects one particular condition from a group, and executes only the code enclosed in the corresponding matching 'CASE' statement.
So it's clearer that the "Select" function in mono-conditional and woks as a Selector for a single Case.
PS. Drop the Case word from the Select Line, it's just confusing.
So it's like this…
Posted
Regular

The most misleading bit of the wiki document for Select is shown in bold:-
_____________________________
Note
The TO keyword can also be used without a lower bound which makes the case like a less than range. For example.
CASE TO 0
will act as CASE < 0 and since the cases are evaluated in succession
chrisRoald
Posted
Regular

Consider
Also consider what happens if x = -7 and we change the Select expression to !
1 guest and 0 members have just viewed this.


