|
|
hi,
On 10/11/2017 21:15, Kenneth wrote:
> After re-reading the various comments, and experimenting with all sorts of
> combinations of things, I have to admit that all of this stuff is still a bit
> difficult to wrap my mind around-- mainly because there's a specific stumbling
> block or two that's giving me a problem.
> I've come up with some examples that probably go to the root cause of my
> remaining misunderstanding.
I'll try.
> My basic question is: When is the #switch() value considered an actual Boolean
> true/false value, vs. a 'simple numerical' value?
the documentation only refers to float values being compared/used.
> Getting back to basics-- e.g., NOT using the strcmp() string-compare function to
> complicate things-- consider the following:
> #declare C = 27;
> (A)
> This works successfully...
> #switch(1) // Boolean 'true'
> #case(C = 27) // a Boolean comparison that's also 'true'
yes, you say "switch when the value is one", and "truth" happens to be
represented as one, so, bingo.
> (B)
> This ALSO works... two 'numerical values' that match
> #switch(27)
> #case(C)
same thing, only now you say "switch when the value is 27".
> (C)This does NOT work (it falls through to the #else clause)...
> #switch(1000) // or 343 or -89 or any other non-zero value
> #case(C = 27) // the Boolean comparison again
how could it? 1000 is not the same as one.
> Regarding (A) and (B), it appears that #switch 'changes its operational mode'--
> depending on the particular 'kind' of #case that it's presented with (Boolean
> true/false vs. a simple number.) Currently, I'm not exactly sure when that might
> happen, given the complexities of all of this inter-related stuff.
again, the Boolean stuff just happens to apply in these "corner cases".
think coincidence.
> Regarding (C), I was under the impression from some earlier comments that
> #switch could use ANY positive/negative value to mean 'true' or (1)-- but that
> doesn't seem to be a correct interpretation. It seems that only #switch(1)
> works.
this isn't about truth, it as simple as "does value A match value B".
> If I could just get past *these* misunderstandings, my world would be a MUCH
> happier place to be in ;-)
I think that if you calculated the value you're interested in beforehand
and then used a variable (only), there'd be much less confusion, for
instance:
#local A = 1;
#switch (A)
#case (1)
#debug concat("one\n")
#break
#case (2)
#debug concat("two\n")
#break
#case (3)
#debug concat("three\n")
#break
#else
#debug concat("oops\n")
#end
now try it with other values for A, 2, etc. hth.
oh, and just to give you a "headache" :-) using the logical not
operator as suggested by Alain? try this (no further savings though):
(!(strcmp(IMG_TYP,AA)&strcmp(IMG_TYP,BB)&strcmp(IMG_TYP,CC)))
;-)
https://en.wikipedia.org/wiki/De_Morgan%27s_laws
Post a reply to this message
|
|