POV-Ray : Newsgroups : povray.general : fundamental question re: #switch/#case/#break : Re: fundamental question re: #switch/#case/#break Server Time
30 Jul 2024 00:28:14 EDT (-0400)
  Re: fundamental question re: #switch/#case/#break  
From: Thomas A  Fine
Date: 24 Nov 2010 12:10:58
Message: <4ced4722$1@news.povray.org>
In article <web.4ceb0f2c2f7b65a8196b08580@news.povray.org>,
Kenneth <kdw### [at] earthlinknet> 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)
         // ELSE if 0-10 do this   ("break" is sort of like "else")
         #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

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