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 08:31:29 EDT (-0400)
  Re: problem using ORs and strcmp() in #switch/#case  
From: Bald Eagle
Date: 8 Nov 2017 06:30:00
Message: <web.5a02ea6a1346e9e05cafe28e0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

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

This should work, as strcmp(IMG_TYPE,AA) _IS_ 0.


> #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.

Which means that it evaluates to TRUE, or 1, which is NOT 0.

Stop thinking in terms of conditional Boolean word results, and think in 0 or 1.

#if (strcmp(IMG_TYPE,AA)=0)
would give a Boolean result of 1.


I think you're stuck thinking about #switch() and #case() as some sort of
semi-Boolean operator, when it's more of a "pick this value from the following
list" function.  Maybe if you think about the whole block like an array [n] and
the #case statements are picking a specific array item (sort of).

{pseudocode}
#if (Case = n)
      #local Return = Array [n]
#end

and

#if (Range > Low & Range < High)
      #local Return = Array [some appropriate n]
#end


Post a reply to this message

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