For /While loops create a local scope. Thus, if you’d like to write a function the outputs variables defined inside of the for /while loop, one must declare these variables as global beforehand, or use a let wrapper.
The contradiction I see is that Julia has a hard time compiling code with global variables. I’ve seen this in my own code as I try to achieve type stability.
My questions are:
- How can I write loops in a way that is type stable, even though I must declare globals?
- Will declaring a global variable outside of a for loop have a significant impact on the performance of my code?