POV-Ray : Newsgroups : povray.pov4.discussion.general : I want to be rid of my stupid mistakes : Re: I want to be rid of my stupid mistakes Server Time
19 May 2024 05:47:54 EDT (-0400)
  Re: I want to be rid of my stupid mistakes  
From: Trevor G Quayle
Date: 22 Jul 2009 10:25:00
Message: <web.4a6720fa97aca27181c811d20@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> Trevor G Quayle <Tin### [at] hotmailcom> wrote:
> > Perhaps the easiest and most universal solution to implement would be to add a
> > global "loop_limit" variable that would set the maximum number of loops allowed
> > (similar to max_trace value).
>
>   Or to add a #for loop construct.
>
>   (I have thrown some suggestions to the team about this.)
>
> --
>                                                           - Warp

Adding the #for loop only solves the problem with a misplaced or missing
increment statement, which is purely a programmer's error that can be largely
avoided with a little diligence by the programmer.  Of course this is the type
of infinite loop scenerio that the OP is referring to.

This will not solve other infinite loop problems that are not related to
programmer error such as conditional statements that are never satisfied due to
some issue that is not superficially apparent.

The #for loop would add some ease and conciseness to the coding end and help
users avoid this programming error, but it would not add any functionality
overall that isn't already achievable through a properly constructed #while
loop.

I am not arguing that there is no need for a #for loop.  As long as it can be
easily instituted and not become more fluff in the machine, I am all *for* it,
and would likely even use it.

Beyond that, I do think now that a loop_limiter variable as I have described may
have some usage in the SDL.  It can help abort and identify existing *infinite*
(or rather, high-count, potentially infinite) loops within the code that are
not apparent to the user in many situations.  It may also be of direct intended
usage where the user wants to force loops to terminate after a maximum number of
iterations for whatever reason (this can be done through coding, but it would be
an added benefit of having the global variable).


One further item on the potential creation of #for loops:  Would they be best
end-bracketted with the general #end statement (as #while, #if, #switch and
#macro all use)? Or would it be more appropriate to add a "#next" statement or
even "#next n" statement instead?  #end would make it more consistent with
current programming practice, but #next would make the #for loop construct more
visible and identifiable.  Along this line of thinking, perhaps more specific
#end statements would also be more appropriate for the other situations as
well: #while/#wend, #if/#endif, #switch/(#send?), #macro/(#mend?).  Of course
you would likely keep the #end functionality for backwards compatibility.



-tgq


Post a reply to this message

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