In JavaScript for loop I can use var
keyword in loop definition something like that:
for (var i=0; i<10; i++) ...
I know scope of the variable i
is not inside the loop but inside function where loop is declared. This it a better notation than declaring local variable i
outside of the loop (the worst notation is declare i
variable in the beggining of function body):
var i;
for (i=0; i<10; i++) ...
My question is about while loop. I'm not able declare variable in while loop definition something like this:
while((var match = re.exec(pattern)) != null) ...
I have to use var
keyword outside of the while loop.
var match;
while((match = re.exec(pattern)) != null) ...
Am I doing something wrong?