for & while loops in SNEX?
-
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++) { }
-
The only loop construct in SNEX is an iterator for a block using the range-based for loop syntax of C++:
-
@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++) { }
-
@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) -
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:
https://github.com/christophhart/HISE/blob/develop/tools/snex_playground/test_files/loop/for_loop2.h
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.https://www.cprogramming.com/c++11/c++11-ranged-for-loop.html