Lua scope problem

In “The Paranoid Android” the default code gives you a"[^%s]+") variable. What I don’t understand is that once you enter a loop like: for i=0,n-1 do the variable is suddenly nil. What the default code does is redefine j inside every loop which is very strange. From lua documentation the variable should be global and work just like it would in every other language.

So the question is: is there some strange scoping rules in lua I don’t understand or is CG improperly implementing lua?