POV-Ray : Newsgroups : povray.general : fundamental question re: #switch/#case/#break : Re: fundamental question re: #switch/#case/#break Server Time
30 Jul 2024 00:21:12 EDT (-0400)
  Re: fundamental question re: #switch/#case/#break  
From: clipka
Date: 27 Nov 2010 05:09:47
Message: <4cf0d8eb@news.povray.org>
Am 26.11.2010 08:50, schrieb Kenneth:
> Jim Holsenback<jho### [at] povrayorg>  wrote:
>>
>> There was a bug discovered with the #break directive behavior that was
>> addressed (with enhancements) by Change 4942 on 2010/04/18 by
>> clipka@cli-pc-xp64 ... I believe things "jive" now
>
> Thanks, Jim. (Clipka's Change 4942 is quoted verbatim in the WIKI, I believe.)

Doesn't seem like that. Original description of change #4942 was as follows:

---------------------
[smp] modified #break semantics; the #break directive can now be used...:

- anywhere within a #case or #range block, to skip to the end of the 
#switch directive (previously, #break was only useful right before the 
next #case, #range or #else directive, to indicate that a slip-through 
was not desired);

- anywhere within a loop block (both #while and #for), to preliminarily 
terminate the loop; and

- anywhere within a #macro block, to preliminarily terminate the macro.

Example for the use in a loop:

#local R = seed(4711);
#for (I, 1, 100)
   #if (rand(R) < I/1000)
     #break // terminate loop early
   #end
   #debug concat(str(I,0,0), " iterations and counting\n")
#end

Where multiple #switch, loop and/or #macro blocks are nested, #break 
will leave only the innermost of these.
---------------------

> So, just so I understand POV's *current* behavior (beta 39): The need for a
> #break before #else is *no longer* necessary to avoid the 'cascading
> TRUE behavior? I.e., (as a simple analogy) does #else now have an 'implied'
> #break before it? Sorry, I'm still having a bit of trouble understanding change
> 4942 if there's NO #break before an #else.

The wording in the Wiki is wrong; in a #switch statement, #else acts 
like a #range that encompasses any possible number (*), i.e. the 
preceding #case or #range must be ended with a #break statement if 
execution should not continue into the #else block.

(* This analogy even goes so far that it is legal - though perfectly 
useless - to place additional #case or #range statements after an #else 
block; even additional #else blocks will not cause POV-Ray to complain. 
Note that this applies only to switch statements though.)


Post a reply to this message

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