HISE Logo Forum
    • Categories
    • Register
    • Login

    for & while loops in SNEX?

    Scheduled Pinned Locked Moved General Questions
    5 Posts 4 Posters 247 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.
    • FortuneF
      Fortune
      last edited by Fortune

      I can't use below loop formats in SNEX. Am I missing something or can't we use these loops in SNEX?

      int i = 1;
      
      while (i<10 && Math.abs(input)>1)
      {
      		
      }
      

      or

      for (int i=0; i<10; i++)
      {
      		
      }
      
      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        The only loop construct in SNEX is an iterator for a block using the range-based for loop syntax of C++:

        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

        FortuneF 1 Reply Last reply Reply Quote 1
        • FortuneF
          Fortune @d.healey
          last edited by Fortune

          @d-healey Thank you for the info. I don't get what the iterator for a block using the range-based for loop syntax is. So the below "for loop" usage can be done with SNEX?

          for (int i=0; i<10; i++)
          {
          		
          }
          
          Matt_SFM 1 Reply Last reply Reply Quote 0
          • Matt_SFM
            Matt_SF @Fortune
            last edited by Matt_SF

            @Fortune in the type section, it says that a
            "block is a wrapper around a preallocated buffer of float numbers“
            Blocks are used for sample processing. You can't do a for loop in SNEX - but would it be possible to define yourself a block (as you do with array) and iterate through it? (I don't know)

            Develop branch
            Win10 & VS17 / Ventura & Xcode 14. 3

            Christoph HartC 1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart @Matt_SF
              last edited by

              Actually all those loop types are supported in SNEX, if you take a look at the SNEX test suite, you'll see a bunch of test cases that use them:

              Link Preview Image
              HISE/tools/snex_playground/test_files/loop/for_loop2.h at develop · christophhart/HISE

              The open source framework for sample based instruments - HISE/tools/snex_playground/test_files/loop/for_loop2.h at develop · christophhart/HISE

              favicon

              GitHub (github.com)

              BTW, most features of the SNEX language are covered by a test file, so if you want to explore what is working, you can build the SNEX playground (tools/snex_playground), then click on the SNEX logo on the top left to load any test (there are about 500 tests in there). It's also a great way of reporting bugs within the SNEX language, so if you find anything, just write a test file that reproduces the issue and I'll add it to the list (that's how I implemented most of the SNEX language features).

              However in most cases you don't need to write these manual loops and can just iterate every value of a container using the range based for loop. This is a known concept in C++ (and for(n in myArray) is the HiseScript equivalent.

              Link Preview Image
              Range-Based For Loops in C++11 - Cprogramming.com

              Learn how to easily loop over containers using the new C++11 range-based for loops--and how to add support for range-based for loops to your own classes!

              favicon

              (www.cprogramming.com)

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

              50

              Online

              1.7k

              Users

              11.7k

              Topics

              101.9k

              Posts