|
![](/i/fill.gif) |
In article <web.4ceb0f2c2f7b65a8196b08580@news.povray.org>,
Kenneth <kdw### [at] earthlink net> wrote:
>See my conundrum? Of course, my little code problem can easily be fixed with
>some #break clauses. But I'm FAR more concerned with my own lack of
>understanding of the logic of this situation.
Simplest way to look at it - successive cases with no break are all
OR'ed together.
"case" means "If this case OR any of the preceding cases in this block
since the last break are true, execute this code"
This lets you conserve code by grouping a bunch of different cases
together. See the "N is prime" example from clipka. But you could
also ADD code for #case(2) that only executes for that, without
separating it out of the conditions for 3,5 and 7:
#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)
// if 0-10 and NOT 2,3,5,7 (because of the "break" above) do this
#debug "N is non-prime\n"
#break
#else
#debug "I don't know the primes >10 by heart\n"
#end
tom
Post a reply to this message
|
![](/i/fill.gif) |