Multiple ORs in an IF statement


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Question Multiple ORs in an IF statement

    Code:
        if COM_KHz_Remainder = 995 then
            COM_KHz_Counter = 000
        else
            COM_KHz_Remainder = COM_KHz_Counter // 100
            if (COM_KHz_Remainder = 20) or
               (COM_KHz_Remainder = 45) or
               (COM_KHz_Remainder = 70) or
               (COM_KHz_Remainder = 95) then
                COM_KHz_Counter = COM_KHz_Counter + 5
            endif
        endif
    I can't seem to find a proper syntax for those quadruple ORs...?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Multiple ORs in an IF statement

    The only way I could get it to compile:

    Code:
        if COM_KHz_Remainder = 995 then
            COM_KHz_Counter = 000
        else
            COM_KHz_Remainder = COM_KHz_Counter // 100
            if COM_KHz_Remainder = 20 then COM_KHz_Counter = COM_KHz_Counter + 5
            if COM_KHz_Remainder = 45 then COM_KHz_Counter = COM_KHz_Counter + 5
            if COM_KHz_Remainder = 70 then COM_KHz_Counter = COM_KHz_Counter + 5
            if COM_KHz_Remainder = 95 then COM_KHz_Counter = COM_KHz_Counter + 5
        endif
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Multiple ORs in an IF statement

    When splitting a statement across multiple lines like that you need to use line extension charachter ( _ ).
    Section 2.17 in the manual.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Multiple ORs in an IF statement

    Code:
            if (COM_KHz_Remainder = 20) or _
               (COM_KHz_Remainder = 45) or _
               (COM_KHz_Remainder = 70) or _
               (COM_KHz_Remainder = 95) then
                COM_KHz_Counter = COM_KHz_Counter + 5
            endif
    That feeling when you missed something totally obvious; well that's what I'm feeling right now.


    And then the REALLY dumb feeling is when you notice you were doing it properly on LCDOUT command all that time...
    Last edited by Demon; - 26th August 2024 at 19:43.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,117


    Did you find this post helpful? Yes | No

    Default Re: Multiple ORs in an IF statement

    Don't worry. It happens to all...!

    Ioannis

Similar Threads

  1. Replies: 5
    Last Post: - 19th September 2016, 10:13
  2. Programming multiple pics with multiple programs
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd April 2013, 17:47
  3. newbe: IF..THEN statement
    By ShawnB in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th November 2009, 14:07
  4. ADC_IN statement
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 15th April 2007, 10:15
  5. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05

Members who have read this thread : 10

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