POV-Ray : Newsgroups : povray.general : array.length()? : Re: array.length()? Server Time
30 Jul 2024 12:28:33 EDT (-0400)
  Re: array.length()?  
From: clipka
Date: 24 Feb 2009 03:40:00
Message: <web.49a3b21678dc09aea5bc7c50@news.povray.org>
"[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
> Is this the best I can hope for? Is there some other way to detect the
> populated length of an array? dimension_size is *useless*. Might it be that
> I am forced to form the array within the loop which uses it? That would
> suck...not very OO...but then SDL isn't very OO to start with, ironically..


Prepared to give yourself a big slap on the head?

Try this (*ta-daaah*):


      -------------------------
       #ifdef (myArray[i]) ...
      -------------------------


So a fail-safe code to loop through an array would look something like this:

#declare i=0;
#while (i < dimension_size(myArray,1))
  #ifdef (myArray[i])
    #debug concat("[", str(i,0,0), "]=", str(myArray[i],0,0), "\n")
    #declare i=i+1;
  #else
    #debug concat("[", str(i,0,0), "] undefined\n")
    #declare i=dimension_size(myArray,1); // force exiting of the loop
  #end
#end

(unfortunately, POV doesn't have a break statement for loops (its #break
statement is only of use in #switch statements), nor does it "short-circuit"
its & operator so #while (i < dimension_size(myArray,1) & defined(myArray[i]))
will not work properly, hence the comparatively ugly way of terminating the
loop)

Or, if your list may contain "holes":

#declare i=0;
#while (i < dimension_size(myArray,1))
  #ifdef (myArray[i])
    #debug concat("[", str(i,0,0), "]=", str(myArray[i],0,0), "\n")
  #else
    #debug concat("[", str(i,0,0), "] undefined\n")
  #end
  #declare i=i+1;
#end


Post a reply to this message

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