HISE Logo Forum
    • Categories
    • Register
    • Login

    If else statement help

    Scheduled Pinned Locked Moved General Questions
    6 Posts 3 Posters 248 Views
    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.
    • R
      rzrsharpeprod
      last edited by

      I am using if/else statements to show and hide some elements in my UI but I'm hoping I can streamline it a bit.

      I have got the basic if/else statements to work eg
      If condition 1 is true do thing A

      I am unsure of the correct syntax for multiple things to happen if the condition is met.

      For example:
      If condition 1 is true do thing A and thing B

      Can somebody point me in the right direction please?

      Thanks in advance

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @rzrsharpeprod
        last edited by

        @rzrsharpeprod Multiple lines need to be in curly braces

        if (condition)
        {
            doThingA();
            doThingB();
        }
        else
        {
            doThingC();
            doThingD();
        }
        
        R 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by

          If it's more than a three you might want to use a switch statement.

          Link Preview Image
          HISE | Docs

          favicon

          (docs.hise.audio)

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          R 1 Reply Last reply Reply Quote 0
          • R
            rzrsharpeprod @A Former User
            last edited by

            @iamlamprey said in If else statement help:

            @rzrsharpeprod Multiple lines need to be in curly braces

            if (condition)
            {
                doThingA();
                doThingB();
            }
            else
            {
                doThingC();
                doThingD();
            }
            

            Thankyou, that makes sense and seems straightforward. I'll give that a go, thanks again

            1 Reply Last reply Reply Quote 0
            • R
              rzrsharpeprod @d.healey
              last edited by

              @d-healey said in If else statement help:

              If it's more than a three you might want to use a switch statement.

              Link Preview Image
              HISE | Docs

              favicon

              (docs.hise.audio)

              Thanks David. Is that for cleaner code and more efficient processing purposes?

              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @rzrsharpeprod
                last edited by

                @rzrsharpeprod It's cleaner code. Probably doesn't make a difference to efficiency in terms of resource usage, but it's more efficient from the point of view of writing and maintaining your code, and readability.

                Also depending on what exactly you're trying to do there might be other ways to write it that are more efficient.

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

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

                40

                Online

                1.7k

                Users

                11.7k

                Topics

                102.0k

                Posts