Nested IF-THEn_ELSEs


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default Nested IF-THEn_ELSEs

    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

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Your second If statement is true for all the conditions so else will never be executed



    Al.
    Last edited by aratti; - 31st October 2008 at 15:22.

  3. #3
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Nested For Next Loop Demo
    By Archangel in forum Code Examples
    Replies: 0
    Last Post: - 8th June 2009, 08:57
  3. Nested IF THEN Statements
    By cjsanders in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th December 2004, 20:18

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts