Forum
    • Categories
    • Register
    • Login

    Declaring variables before a for loop necessary in some cases?

    Scheduled Pinned Locked Moved Scripting
    1 Posts 1 Posters 14 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.
    • CyberGenC
      CyberGen
      last edited by

      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.

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

      22

      Online

      2.2k

      Users

      13.4k

      Topics

      116.3k

      Posts