PDA

View Full Version : Nested IF-THEn_ELSEs



ardhuru
- 31st October 2008, 14:57
I just cant figure this out. On searching the forum, I found this thread http://www.picbasic.co.uk/forum/showthread.php?t=6313 that seems kind of relevant, but I still dont understand this.

IF ONTIME > OFFTIME THEN
IF TIME => ONTIME or TIME < OFFTIME THEN
Green = 1
RED = 0
ELSE
GREEN = 0
RED = 1
ENDIF
ENDIF

In the code above, when the 2nd condition is not met, I would expect Green = 0 and Red = 1, right? That doesnt seem to happen; Green stays 1 and Red stays 0. Am I doing something wrong with the 'Else' command?

Thanks in advance!

Regards,

Anand

aratti
- 31st October 2008, 15:19
Your second If statement is true for all the conditions so else will never be executed



Al.

ardhuru
- 31st October 2008, 17:28
Okay folks, my stupidity. I was using bi-color LEDs, and they were CAs; that made things a bit confusing. Its working the way its supposed to now.

Anand