|
![](/i/fill.gif) |
"[GDS|Entropy]" <gds### [at] hotmail com> 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
|
![](/i/fill.gif) |