+ 1

What does this mean

In an array someone defined it as arr then said for(x=0;x<arr.length;x++) What does this mean and what does it do

11th Mar 2018, 10:15 PM
Someone Else
Someone Else - avatar
5 odpowiedzi
+ 1
its an for loop. its work likr this for(x=0;x<arr.lenght;x++) its define x's value as 0 if zero is bigger than arr.lenght(number of character in an array).x will be plus one
11th Mar 2018, 10:19 PM
Blizz
Blizz - avatar
+ 1
for example = var arr = [5,2,0,1] //this array's length is 4 for(x=0;x<arr.length;x++) //if x is still smaller than 4 it will be plus by one so x is 4
11th Mar 2018, 10:22 PM
Blizz
Blizz - avatar
+ 1
How come someone used it in a snake game for the tail length ?
11th Mar 2018, 10:23 PM
Someone Else
Someone Else - avatar
+ 1
The loop for while repeat instructions while the condition is true. You have 3 parts seperated by semilicons: -the definition of the variable you'll use in the condition -the condition -the operation to change the value of the variable So the condition with words means: while x is smaller than the length of the variable arr When the loop is finished, the new value of x is x+1. After that, the computer will check if the condition return true or false. If true, it run the loop again, if false, it stop the loop
11th Mar 2018, 10:24 PM
Nobody
+ 1
@jerome many people use loop to making map because it is short to write
11th Mar 2018, 10:25 PM
Blizz
Blizz - avatar