+ 2

please explain this condition

for(var x=0;x<arr.length;x++)

22nd Sep 2016, 12:51 PM
wulture
6 Réponses
+ 6
Whatever code is within the braces of the for loop signature, it will be ran until the control variable is no longer less than arr.length.
22nd Sep 2016, 11:25 PM
Ousmane Diaw
+ 4
for loop executes a code while the condition remains true. the condition is specified in the first set of parenthesis of the for loop. x =0 sets ur variable at zero. .length specifies the amount of variables or objects in an array. if x is 0 and arr has 3 variables or objects in it the code will execute as long as x is smaller than the length of the array. it will do this once for each number of objects that is in the array and will not stop executing until the number executions is greater than the number of length in the array. ++ is an increment telling us that the variable will increase by one each time the code is executed(which just really means that it will execute more than once. if x is incremented by one the next condition is (x=1;x<arr.length) then it increments again (x=2;x<arr.length) until the number of X is equal to or higher than the number of objects in an array. the first two instructions are carried out first, then increments, then it is repeated...
24th Sep 2016, 4:58 PM
Dion Matthew Levy
Dion Matthew Levy - avatar
+ 3
arr . lengt is number of var . for exemple var arr=[a, b, c] then arr. length =3
23rd Sep 2016, 2:17 PM
sagir
sagir - avatar
+ 1
it's still not clear. can anyone explain it a little more easily and depth.
23rd Sep 2016, 4:34 PM
wulture
+ 1
yav for loop un neyini aciklayam bacim
24th Sep 2016, 10:55 AM
sagir
sagir - avatar
+ 1
loop an array from head to the end.Is it a simple explanation?
10th Oct 2016, 2:17 PM
William Jing
William Jing - avatar