POV-Ray : Newsgroups : povray.advanced-users : problem using ORs and strcmp() in #switch/#case : Re: problem using ORs and strcmp() in #switch/#case Server Time
29 Apr 2024 07:09:42 EDT (-0400)
  Re: problem using ORs and strcmp() in #switch/#case  
From: Kenneth
Date: 7 Nov 2017 23:45:00
Message: <web.5a028a351346e9e089df8d30@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:


>
> Also, there's a much easier way to achieve a logical OR in any `#switch`
> construct: Just place multiple `#case` statements without a `#break` in
> between, like so:
>
>     #switch(0)
>       #case(strcmp(STRING,CONST1A))
>       #case(strcmp(STRING,CONST1B))
>         // go here if STRING = CONST1A or CONST1B
>       #break
>       #case(strcmp(STRING,CONST2A))
>       #case(strcmp(STRING,CONST2B))
>         // otherwise go here if STRING = CONST2A or CONST2B
>       #break
>
I didn't know that using #cases without #breaks was possible :-O  Thanks! That's
the construction I will probably use; it's nice and elegant. In fact, so
interesting that a note in the documentation about it would be justified ;-)

BTW, I almost never use #switch(true) in my scenes, usually just #switch(1) or
#switch(0)-- believing that they are the 'logical equivalents' of true/false,
not just the 'number values' 1 and 0. It has always worked for me, but is my
assumption valid, in light of all that's been said?

Another question, just to clarify something: Is there a difference between the
following two examples? (I don't actually code the latter way-- it may not even
be appropriate-- but I've seen various types of non-strcmp() constructions in
the newsgroups that look similar)...

#switch(0)
#case(strcmp(IMG_TYPE,AA))

and

#switch(0)
#case(strcmp(IMG_TYPE,AA)=0)

I ask because the latter doesn't work--no error message of any kind is created,
but it falls through to the #else clause, even though strcmp(IMG_TYPE,AA) is a
'match' between IMG_TYPE and AA.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.