Can anyone explain to me how internally vortex handles $next variable inside nested loop? This could cause serious problems especially when calling functions.
If we have two nested loops, after leaving the inner loop, $next variable value is not set to the $next variable value of outer loop.
$loop and $next are set at the top of the loop and may be overwritten anywhere in the loop, as you've found. They will resync on the next iteration of the loop.
If you're relying on their values in circumstances where they may be overwritten you should save them at the top of the loop and use the saved versions:
<loop $somevar>
<local savenext=$next saveloop=$loop>
...
</loop>
Why have they decided upon such a design of language? Is there a particular reason, e.g. the execution speed?
I understand that I have to use a local variable. I am more interested in the underlaying mehanism of vortex.
If $loop etc automatically "popped" to the outer <loop> values after the <sql></sql> you would not know how many the <sql> loop returned. One may do the same with an inner <loop> and look to $loop for the count rather than using <count> which may not be accurate if one were to <break> out of the <loop> early.