var I=0;
While (iThe console. The log (arr [I]);
i++;
}
The console. The log (I)
The while loop completely equivalent you for loop,
You can see only i
After exit the loop I value is 5,
CodePudding user response:
1. Use var to define variables inside the for loop is equivalent to the global declarations2. The for loop every time I add 1, and then judge whether I meet the conditions, not satisfied will terminate the loop
3. Run to I=4 when I less than arr. The length (the length of 5), so do a loop body, I accumulate into five at a time, to judge whether meet the loop condition next time, don't meet, cycle is terminated, I no longer accumulation, therefore, I to 5