Integer A/B are globals. If you have a Wait action inside the loop, another trigger might fire meanwhile and change the value of A/B or the ending values of your iteration are stored inside globals, too. Even without Waits you could have actions in the loop body that potentially trigger events immediately. If your code has to be recursion-safe, even a dedicated global variable won't be enough. In Jass, you have the possibility to declare local variables, which are instanced everytime you run the function they belong to, so each call of the function is sovereign.