please explain this condition | SoloLearn: Learn to code for FREE!


please explain this condition

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

9/22/2016 12:51:25 PM


6 Answers

New Answer


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.


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...


arr . lengt is number of var . for exemple var arr=[a, b, c] then arr. length =3


it's still not clear. can anyone explain it a little more easily and depth.


yav for loop un neyini aciklayam bacim


loop an array from head to the end.Is it a simple explanation?