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
1 May 2024 08:36:17 EDT (-0400)
  Re: I want to be rid of my stupid mistakes  
From: Trevor G Quayle
Date: 21 Jul 2009 09:50:00
Message: <web.4a65c76797aca27181c811d20@news.povray.org>
"clipka" <nomail@nomail> wrote:
> "scott" <sco### [at] scottcom> wrote:
> I do know I keep repeating myself, but: Why on earth try to come up with
> ever-so-complex ways to detect a broken counting #while loop without breaking
> other uses of the #while statement, when really the root problem is the absence
> of a proper #for loop?
>
> Virtually no-one is asking for an infinite loop detection in other languages
> like Pascal, C, VB or what-have-you. Why? Because they do have a for-loop so
> you usually don't encounter this blunder there.


I really dont see the need for a FOR loop.  In the most general sense, FOR loops
just increment from one value to another at a preset interval.  FOR loops are
essentially just specialized WHILE loops and very easy to implement in POV
without causing errors.

FOR i = 1 to 6 STEP j
  ...
NEXT j

#declare i=1; #while (i<=6)
  ...
#declare i=i+j; #end

Most of the infinite loop situations that have been presented would not be
solved properly with a FOR loop.  For example, any of the conditional increment
type loops (counter is increased only if a certain condition is met) require
extra steps in a FOR loop to work:

#declare i=1; #while (i<6)
  ...
  #if(condition)
    #declare i=i+j;
  #end
#end


FOR i = 1 to 6 STEP j
  ...
  IF (NOT condition)
    i=i-j
  ENDIF
NEXT j


I don't think that there are any 'infinite loop' detectors that would be of
universal value to add to POV.  I little bit of diligence and debugging on the
part of the user can easily overcome any issue.  In the past, whenever I have
put together a #while loop that isn't working properly, setting up value
reporting with the #debug statement usually was able to show if a value wasn't
progressing as expected and help pinpoint the problem.

-tgq


Post a reply to this message

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