POV-Ray : Newsgroups : povray.general : How to quick filling an array : Re: How to quick filling an array Server Time
29 Jul 2024 10:29:40 EDT (-0400)
  Re: How to quick filling an array  
From: Cousin Ricky
Date: 7 Oct 2011 17:00:00
Message: <web.4e8f6738bbede7878641e0c0@news.povray.org>
Alain <aze### [at] qwertyorg> wrote:
> As you probably don't need the indexing variables outside the
> initialisation, and you surely don't need to keep the final values, you
> can use #local.
> That way, the variables will not exist once the loops are terminated.

This is true of macros and include files.  It does not apply to loops.

Try this scene file:
_________________________________________

#declare MyArray = array[5][10];
#local I = 0;
#while (I < 5)
   #local J = 0;
   #while (J < 10)
      #declare MyArray[I][J] = 0;
      #local J = J + 1;
   #end
   #local I = I + 1;
#end

text
{  ttf "cyrvetic.ttf" str(I,0,1) 0.001, 0
   translate <-1, 0.2, 2>
   pigment { rgb 1 }
   finish { ambient 1 }
}

text
{  ttf "cyrvetic.ttf" str(J,0,1) 0.001, 0
   translate <-1, -0.8, 2>
   pigment { rgb 1 }
   finish { ambient 1 }
}
_________________________________________

The identifiers I and J can be referenced even after the loops are closed.  J
can be referenced even though it's declared only inside the I loop.


Post a reply to this message

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