|
![](/i/fill.gif) |
Alan Grainger wrote in message <35afb2de.0@news.povray.org>...
>How do you exit from a macro? For instance, you have called a macro, and a
>certain condition is reached, and you want the macro to exit. How?
You can do it all with "whiles" and "ifs" (actually with "whiles" alone, but
"ifs" are nicer sometimes):
Your version:
>#macro DoMacro ( a, b, c )
> blah blah...
> #if ( something = true )
> #endmacro
> #end
> more junk...
>#end
becomes:
#macro DoMacro( a, b, c )
blah blah...
#if (something = false)
more junk...
#end
#end
and this one:
>#macro DoMacro ( a, b, c )
> blah blah 1...
>here:
> blah blah 2...
> #if ( something = true )
> #goto here
> #end
> more stuff...
>#end
becomes:
#macro DoMacro ( a, b, c )
blah blah 1...
#declare first_time = true
#while (something = true | first_time)
blah blah 2...
first_time = false
#end
more stuff...
#end
(I'm not sure that I got the syntax right, but you catch my meaning).
One of the first things you learn in advanced programming courses (and even
in good general/basic ones) is, that you don't need "Goto" at all.
Everything can be written in much better and readable style with "ifs" and
"whiles".
Simply ask yourselve whenever you crave for a "Goto": "How can I do it
without?". There always is an answer, and after some time you will find
yourself using "Goto" less and less, until it becomes natural not to use it.
Although it would be nice if POV-Ray had the other kind of while (which is
executed at least once), which would
create code without the "first_time" thing:
#macro DoMacro ( a, b, c )
blah blah 1...
#do
blah blah 2...
#while (something = true)
more stuff...
#end
Hope it helps,
Johannes.
Post a reply to this message
|
![](/i/fill.gif) |