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:26:34 EDT (-0400)
  Re: problem using ORs and strcmp() in #switch/#case  
From: Kenneth
Date: 11 Nov 2017 13:55:01
Message: <web.5a0746151346e9e089df8d30@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 10.11.2017 um 22:15 schrieb Kenneth:

> > If I could just get past *these* misunderstandings, my world would be a MUCH
> > happier place to be in ;-)
>
>
> I'd also like to re-iterate that the above constructs are all
> "upside-down" usages of the `#switch` statement. The intentional use is
> to specify a variable expression-to-be-examined in the `#switch`
> statement itself, and constant expressions-to-match in the `#case` (or
> `#range`) statements.

Ah, I see! That's actually a revelation to me, and probably my major stumbling
block. I've always thought of #switch/#case in the 'upside-down' mode-- that
the #switch should contain the Boolean 'trigger' of 0 or 1, and the #case
statements should contain the variables-- a configuration that just seems more
natural to me for some reason (although it obviously leads to problems!)  And,
my *original* (non-working) example of using #switch(1000) was admittedly out of
desperation, to get it to 'numerically agree/disagree' with
(strcmp(IMG_TYPE,AA) + 1000) and its brothers.

So it looks like even my final *successful* scene example of...
#switch(1)
#case((strcmp(IMG_TYPE,AA)=0)
....etc...

....is also 'upside down'. In fact, it also now looks like quite a 'special
case', because of my use of strings and strcmp() rather than 'typical'
variables. But re-configuring this to be 'right-side-up' looks to be difficult,
*because* of its special-case nature and the many 'string constants' I'm using
(AA,BB,CC etc.) It looks like I actually need the upside-down strategy, for my
particular scene.

I finally got around to reading the Wikipedia article about the #switch
statement-- which has subtle operational differences depending on the
programming language. But I came across this--in 'Alternative Uses', ha...

"...in PHP, a constant can be used as the "variable" to check against, and the
first case statement which evaluates to that constant will be executed. This
feature is also useful for checking multiple variables against one value rather
than one variable against many values."

That looks like part of my (mis-)conception of switch/case's NORMAL operation!

Now I need to re-digest this entire post in light of this 'new' discovery; it's
almost a paradigm shift.  :-O


Post a reply to this message

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