Declaring variables before a for loop necessary in some cases?
-
Hi friends, it's been a minute.
So my question is about declaring loop variables before a for loop, given that HISE doesnt like it inside the loop.
There seems to be conflicting guidance (and examples in the wild) about whether loop variables should be declared beforehand, and how much they can interfere with other functions.
Both versions seem to work most of the time, but in larger namespaces with many inline functions, I’ve seen odd behavior that looks like iterator variables leaking or being reused across functions (off-by-one bugs, wrong source index, etc.).
My questions
Are loop variables (i, s, n, etc.) implicitly local to the inline function, or are they shared unless explicitly declared local?
Is it considered best practice to always declare loop iterators as local at the top of each inline function?
Can undeclared loop variables interfere with other inline functions in the same namespace, or is that a myth?
I'm looking for some clarity as I’m trying to decide whether it’s worth doing a cleanup pass where every inline function explicitly declares its loop iterators (e.g. local i, s, n;) to avoid subtle bugs, or whether that’s unnecessary.
Thanks.