Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    A neater way of doing this?

    Coding
    5
    8
    457
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SteveZX81
      SteveZX81 F last edited by MikeDX

      I have this line

      If (ti[0] == 3) and (ti[1] == 3) and (ti[2] == 3) and (ti[3] == 3) and (ti[4] == 3) and (ti[5] == 3) and (ti[6] == 3) and (ti[7] == 3) and (ti[8] == 3) and (ti[9] == 3)
      

      I wish to find a much neater/shorter way of doing it, what do you suggest?
      (I only wish something to trigger if all 10 of ti[0-9] are equal to 3. not one or two, but all of them)

      1 Reply Last reply Reply Quote 0
      • Jaywalker
        Jaywalker Donator last edited by

        allTrue = true
        for i = 0 to 10 loop
        if ti[i] != 3 then
        allTrue = false
        break
        endif
        repeat
        
        if allTrue then
         //Do what you gotta do
        
        
        1 Reply Last reply Reply Quote 3
        • Discostew
          Discostew F last edited by

          Had something similar to what @Jaywalker posted, but mine went through all of them rather than breaking the moment it found something not true. If this is something you plan to do for multiple different instances, you could convert it to a function and just call the function each time instead

          function isAllEqual( arr, tst )
            ret = true
            for i = 0 to len( myarray ) loop
              if( arr[ i ] != tst ) then
                ret = false
                break
              endIf
            repeat
          return ret
          
          if ( isAllEqual( ti , 3 ) ) then
            // doot doot doot
          else
            // nah nah nah
          endIf
          
          1 Reply Last reply Reply Quote 0
          • SteveZX81
            SteveZX81 F last edited by

            Thank you! it works.

            1 Reply Last reply Reply Quote 0
            • ITzTravelInTime
              ITzTravelInTime F last edited by

              Remember that those kinds or ripetitve checks in which for example just one index changes beetween each condition can be always be done using a for cycle

              1 Reply Last reply Reply Quote 0
              • D
                donaldp last edited by

                On line 4, i read != what is the difference between == and !=

                I am just at the beginning of reading the help section

                Thanks

                Discostew 1 Reply Last reply Reply Quote 0
                • Discostew
                  Discostew F @donaldp last edited by

                  @donaldp said in A neater way of doing this?:

                  On line 4, i read != what is the difference between == and !=

                  I am just at the beginning of reading the help section

                  Thanks

                  == means "is equal to"
                  != means "is not equal to"

                  D 1 Reply Last reply Reply Quote 0
                  • D
                    donaldp @Discostew last edited by

                    @Discostew thanks!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post