Agreed, it does seem odd. I think it's like Bernd said, the structure acts like a logical OR operation.FourthWorld wrote:While the code in the OP works as the Dictionary describes, I'm not sure the implementation is best. After all, the block in question about item 4 leads with a case that evaluates to false, so while I would expect all others to fall through I would not intuitively expect that case to fire.
0 > 1. So is empty
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: 0 > 1. So is empty
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: 0 > 1. So is empty
Jacque.
Right. This is standard form, though here "ganged" cases all point to a single command, and break out explicitly. The "conditionals" are inherent in the parameter following each case instance.
I thought you had done what I presented, where each case may or may not fire:
So if you invoked this with (pseudo):
you would get "pet bird", and nothing else.
Craig
Right. This is standard form, though here "ganged" cases all point to a single command, and break out explicitly. The "conditionals" are inherent in the parameter following each case instance.
I thought you had done what I presented, where each case may or may not fire:
Code: Select all
switch
case pChoice contains "carrot" or pChoice contains "beans" or pChoice contains "lettuce"
put "vegetable" & return after tObject
case pChoice contains "tame" or pChoice contains "houseBroken" or pChoice contains "personal"
put "pet" & return after tObject
case pChoice contains "dog" or pChoice contains "cat" or pChoice contains "mouse"
put "mammal" & return after tObject
case pChoice contains "parrot" or pChoice contains "sparrow" or pChoice contains "hummingbird"
put "bird" & return after tObject
end switch
Code: Select all
put "houseBroken parrot" into pChoice
run the switch
Craig
Re: 0 > 1. So is empty
If you swap cases 2 and 3, you do get "pet bird". It appears to run through all cases after the first match. If there are no matches you get nothing.
I have used conditional cases in the past but I can't remember where, and I don't remember whether there were fallthroughs or not. I know I've never hit the issue we're discussing though. Maybe the LC team will agree with your report.
I have used conditional cases in the past but I can't remember where, and I don't remember whether there were fallthroughs or not. I know I've never hit the issue we're discussing though. Maybe the LC team will agree with your report.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: 0 > 1. So is empty
Jacque.
The trick is not to have to order the case statements so that they perform the way you need them to. The trick is to have the condititionals determine the way things perform.
Craig
The trick is not to have to order the case statements so that they perform the way you need them to. The trick is to have the condititionals determine the way things perform.
Craig
Re: 0 > 1. So is empty
Hi,
ever avoided "switch/ case" for this. I just don't get the way it works.
I'd expect:
- if there is a "break" in the first "true statement", it exits at it.
- if there is no "break" in a "true statement", it & all following "true statements" are executed.
(Until one has a break)
So basically:
- "break" in a "true statement" exits after execution
- no "break" means other following "true statements" are executed, until one has "break" or the loop ends.
- "false statements" are never executed.
I may be completely wrong, for sure :)
As mentioned, it confuses me - so I keep my hands off ;-)
Have fun!
ever avoided "switch/ case" for this. I just don't get the way it works.
I'd expect:
- if there is a "break" in the first "true statement", it exits at it.
- if there is no "break" in a "true statement", it & all following "true statements" are executed.
(Until one has a break)
So basically:
- "break" in a "true statement" exits after execution
- no "break" means other following "true statements" are executed, until one has "break" or the loop ends.
- "false statements" are never executed.
I may be completely wrong, for sure :)
As mentioned, it confuses me - so I keep my hands off ;-)
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: 0 > 1. So is empty
AxWeld.
My point from the start was that, without explicit "break" lines, after a "true" evaluation, subsequent case statement conditionals which evaluate to "false" are executed as well. That seems unseemly to me.
What I assumed, and filed an enhancement request for, was that a series of case statements without breaks would fire based solely on their evaluations. In other words, you are not forced to exit the construction at the first "true" evaluation; you may continue and perhaps find others.
This may actually have gotten the attention of the team, as they have confirmed the situation, and indicated they are working on it.
We will see...
Craig
My point from the start was that, without explicit "break" lines, after a "true" evaluation, subsequent case statement conditionals which evaluate to "false" are executed as well. That seems unseemly to me.
What I assumed, and filed an enhancement request for, was that a series of case statements without breaks would fire based solely on their evaluations. In other words, you are not forced to exit the construction at the first "true" evaluation; you may continue and perhaps find others.
This may actually have gotten the attention of the team, as they have confirmed the situation, and indicated they are working on it.
We will see...
Craig