Home > front end >  Why output 5 hope, detailed points
Why output 5 hope, detailed points

Time:09-25

Var arr=,2,3,5,66 [1] for (var I=0; i CodePudding user response:

Circulation to i CodePudding user response:

You write i CodePudding user response:

Change a for loop to the equivalent of a while loop is well understood,
 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 iThere are five elements in the array, you arr. Length value is 5, so only I was 5 cases judgment to false to withdraw from circulation,
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 declarations
2. 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