|
![](/i/fill.gif) |
Kenneth wrote:
> "Kenneth" <kdw### [at] earthlink net> wrote:
>
>> Something like,
>> "For example, if you use a series of #case or #range clauses with no #
breaks
>> in-between, the first clause that evaluates TRUE will force all subseq
uent
>> clauses to evaluate TRUE as well (regardless of their intrinsic TRUE/F
ALSE
>> conditional state), in a sort of cascade--until a #break/#else/#end is
>> encountered." Or something similar.
>>
>
> And this 'cascade effect' can also affect the behavior of #else, kind o
f a
> 'gotcha' (as I discovered, now that I halfway-know what I'm doing!) I'
ll use
> the "N=prime" code as an example (with a few additions of my own)...
>
> #declare N = 6;
> #switch(N)
> #case(2)
> // if 2, do this
> #debug "I like this number a lot!\n"
> #case(3)
> #case(5)
> #case(7)
> // if 2, 3, 5, or 7, do this
> #debug "N is prime\n"
> #break
> #range(0,10)
> #debug "N is non-prime\n"
> #range(20,30)
> #debug "range(20,30) is also TRUE\n"
> #range(40,50)
> #debug "range(40,50) is also TRUE\n"
> // #break
> #else // do this for anything over 10
> #debug "Oops, I don't know the primes >10 by heart\n"
> #end
>
> Note that I purposely commented-out the final #break clause. (I say thi
s because
> initially, I didn't think it was necessary. But it is.)
>
> The docs about #else say, "It is only executed if the clause before it
was a
> false clause."
>
> Let's say N=6. The first clause to be evaluated TRUE is #range(1,10).
Now
> without thinking, it might appear that the final #range(40,50) would be
> evaluated false (because N doesn't fall in its range). But because of t
he
> 'cascading TRUES' of the #ranges above it, it's actually TRUE. And, con
tinuing,
> the #else conditional in this case is also forced TRUE (if that's the c
orrect
> term), and #else's token is also printed to messages. So the #break cla
use
> before #else is a necessity, to get an expected outcome from it.
>
The doc explicitly states the opposite: "parsing continues until a
#break, *#else* or #end directive is reached", so this is a bug
(either in povray or in the docs).
Jerome
--
mailto:jeb### [at] free fr
http://jeberger.free.fr
Jabber: jeb### [at] jabber fr
Post a reply to this message
Attachments:
Download 'us-ascii' (1 KB)
|
![](/i/fill.gif) |