POV-Ray : Newsgroups : povray.newusers : Is there a for operator? : Re: Is there a for operator? Server Time
28 Jul 2024 14:31:54 EDT (-0400)
  Re: Is there a for operator?  
From: Christian Froeschlin
Date: 9 Oct 2008 18:41:52
Message: <48ee88b0@news.povray.org>
Mathuin wrote:

> I don't think assignments, comparisons, or statements can be passed as macro
> arguments, but if they could be, something like this would almost work:
> 
> #macro for(init, check, inc, body)

well, in case somebody loves odd syntactic constructs, here
is a somewhat silly macro for a counter-based loop, although
in this form not nestable for multiple loops:

#macro FROM_TO(FROM,TO)
#local i = FROM;
#while (i < TO)
   FOR(i)
   #declare i = i + 1;
#end
#end

Ponder it for a while and scroll down if confused ;)





...





Scroll some more





...





// Here is how to actually write a loop with it:
#macro FOR(I)
   sphere {<I,0,0>,1 pigment {color rgb 1}}
#end FROM_TO(0,10)





... and what a good thing that macros can be redefined ;)


Post a reply to this message

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