PBJim wrote: Wed Apr 30, 2025 10:56 am
Do you have an example of what you would like to do but can't?
To be honest, I'm fairly happy with PureBasic's case statement as it is Demivec. It follows a very common form of specifying the argument once, within the Select statement, so there's a practical constraint in terms of how that might become more elaborate or extended further.
However, since you asked, to give a comparison with others — some languages provide the complete argument and conditional evaluation within each Case clause, thus making their logic independent of each other. That approach shifts the scope of Select beyond logic conditions relating to a single value argument, potentially better representing business logic or rules which aren't concerned merely with one value. But as I say, PureBasic — indeed like many languages — already takes a different intrinsic approach and perhaps it's difficult therefore to integrate something like the below, without resorting to adding a new language statement altogether :
Code: Select all
begin case
case acctype = "C" and amount > cutoff
.. do something
case delflag = "D" or acctype = "D"
.. do something
case amount > limit
.. do something
case 1
.. do the default
end case
Note — above reproduced from the same forementioned thread at
viewtopic.php?p=617685#p617685
I'm not advocating doing this, as I think PureBasic's scope in this regard is okay and it's important to be sympathetic towards the developers' resources. Still good to chat about it though

[/quote]
Your example case (pun intended) can be handled quite easily:
Code: Select all
Procedure decide(acctype.s, delflag.s, amount.i, limit.i, cutoff.i)
Select #True
Case Bool((acctype = "C") And (amount > cutoff))
Debug "acctype('" + acctype + "') = 'C' And amount(" + amount + ") > cutoff(" + cutoff + ")"
;.. do something
Case Bool((delflag = "D") Or (acctype = "D"))
Debug "delflag('" + delflag + "') = 'D' Or acctype('" + acctype + "') = 'D'"
;.. do something
Case Bool(amount > limit)
Debug "amount(" + amount + ") > limit(" + limit + ")"
;.. do something
Default
Debug "Default, acctype('" + acctype + "'); delflag('" + delflag + "'), amount(" + amount + "), limit(" + limit + "), cutoff(" + cutoff + ")"
;.. do the default
EndSelect
Debug LSet("", 40, "-")
EndProcedure
decide("C", "D", 30000, 8000, 29800)
decide("C", "D", 2550, 8000, 29800
decide("D", "A", 2550, 8000, 29800)
decide("A", "N", 2, 8000, 29800)
decide("A", "N", 8001, 8000, 29800)
decide("B", "D", 10000, 8000, 29800)
decide("C", "A", 75, 8000, 29800)
The first case that evaluates to #True will be acted upon. I only added some additional parenthesis to group the conditions and the debug statements to show the values of the variables.
As I said, it may not result in a speed improvement over a series of If/EndIf statements but it does give some clarity in showing the precedence of the conditions being tested for.