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
2 May 2024 05:56:22 EDT (-0400)
  Re: problem using ORs and strcmp() in #switch/#case  
From: Alain
Date: 9 Nov 2017 19:13:03
Message: <5a04ef0f$1@news.povray.org>
Le 17-11-08 à 15:56, Kenneth a écrit :
> SO...
> With all of this new-found knowledge, I actually came up with some code that
> works consistently-- and that still uses my original OR statements(!)
> 
> #switch(1)
>      #case(
>       (strcmp(IMG_TYPE,AA)=0) // if strcmp(...) returns zero, then 0=0 is 'true',
> // which matches #switch. Otherwise, 'false'.
>       | (strcmp(IMG_TYPE,BB)=0) // ditto
>       | (strcmp(IMG_TYPE,CC)=0) // ditto
> 
> This construct also works in my real scene code, I'm happy to say. (And with the
> ORs in any order.) I prefer the ORs because the real scene has numerous #case
> clauses, each with four or five strcmp()s.  It all simply looks more compact
> this way, to my eyes.
> 
> It's all starting to make sense to me now (although I still need to digest some
> of the comments.) I also see that there are, as usual, various ways to get
> similar results.
> 
> THANKS for taking the time with the insights, examples, and discussion! (And if
> I'm still not 'getting it', don't hesitate to say so!)
> 
> 
> 
> 

Want something even more compact?
Try this :
(!strcmp(IMG_TYPE,AA))|(!strcmp(IMG_TYPE,BB))|(!strcmp(IMG_TYPE,CC))

The "!" is the NOT operator. If the value is zero, it becomes a 1, if 
it's  <>0, it becomes a 0.


Post a reply to this message

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