|
![](/i/fill.gif) |
Am 22.11.2010 11:40, schrieb Kenneth:
> *HOWEVER*, while writing this post, I now see that there might be two
> mutually-exclusive explanations of how #case/#break directives work, in two
> different places in the WIKI:
>
> http://wiki.povray.org/content/Documentation:Reference_Section_2.5
> says, "If a clause evaluates true but no #break is specified, the parsing will
> fall through to the next #case or #range and that clause conditional is
> evaluated." [This seems clear to me--it's the behavior I expected, as the
> wording is the same in the v3.6.1 included documentation.]
>
> whereas at
> http://wiki.povray.org/content/HowTo:Use_conditional_structures
> it says, "When processing a matching #case or #range clause, if a #break is not
> encountered it continues through successive #case statements whether they match
> or not." [This would, I think, explain the behavior I'm seeing; so this must be
> the accurate explanation.]
>
> An honestly naive question: Which mode of operation *should* be correct,
> compared to other standard computational languages?
The switch syntax appears to mimick the syntax of C, which also uses the
"slip-thru" concept, i.e. if you don't insert a "break;", the next block
of statements will be executed even if the case value doesn't match.
C++, Java, JavaScript and C# also use this concept (no surprise though,
as they all have inherited a lot of syntax from C).
The idea behind this is that you can write stuff like:
#switch(N)
#case(2)
#case(3)
#case(5)
#case(7)
#debug "N is prime\n"
#break
#range(0,10)
#debug "N is non-prime\n"
#break
#else
#debug "I don't know the primes >10 by heart\n"
#end
It should be noted that the Missing Break Error is a well-known source
of bugs in C-derived languages, so the fact that it's in these languages
is in no way a sign of quality ;-)
Post a reply to this message
|
![](/i/fill.gif) |