POV-Ray : Newsgroups : povray.binaries.tutorials : #if...#else...#HELP!!! : Re: #if...#else...#HELP!!! Server Time 6 Jun 2023 21:58:04 EDT (-0400)
 Re: #if...#else...#HELP!!!
 From: Philippe Debar Date: 3 Sep 1998 18:13:47 Message: <35ef068b.0@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#35ef068b.0%40news.povray.org",
"dateCreated": "1998-09-03T22:13:47+00:00",
"datePublished": "1998-09-03T22:13:47+00:00",
"author": {
"@type": "Person",
"name": "Philippe Debar"
}
}
Hi Dave

#if (clock<=1)
translate <0, clock*20, 0>
#else
#if (1<clock<=2)
#declare elseclock = clock-1
translate <0, 20, 0>
rotate <0, 0, ((clock-1)*180)>
#else
#if (2<clock<=3)
translate <0, -20, 0>
#else
#if (clock<=4)
#declare elsclock= clock-3
translate (-20+(20*(clock-3)))*y
#end
#end
#end
#end

Why it doesn't work: (or so I believe)
(1<clock<=2)
pov first evaluates 1<clock and returns either false (=0) or true
(=1), then it check the resulting boolean<=2, which is always true...
you should write ((1<clock)&(clock<=2)).

However, there is a simpler way to do this: #switch

#switch (clock) // use clock for all tests
#range (0,1) // if 0<=clock<=1, then...
translate <0, clock*20, 0>
#break //<-- this exit the #switch test, so #range(1,2) isn't used
too when clock=1
#range (1,2)
translate <0, 20, 0>
rotate <0, 0, ((clock-1)*180)>
#break
#range (2,3)
translate <0, -20, 0>
#break
#range (3,4)
translate (-20+(20*(clock-3)))*y
#break // this one isn't necessary... but it is neater this way.
#else
#error "\nClock out of range" // just for fun
#end // close the #switch directive

#switch uses also #case(aValue), but in this case this isn't very
usefull - except if you want subliminal images :-) See the doc.

Hope this helps,

Povingly,

Philippe
```