...

View Full Version : i++ not working in loop :S



martynball
06-18-2012, 06:31 PM
For some reason the i variable is not increasing by 1 for each loop :S

Here is the array:


r,w

Array length is 2.

Function:


//Search arrays
function array_search(array, src) {
for ( var i = 0; i < array.length; i++ ) {
alert(i);
if (array[i] == src) {
return true;
} else {
return false;
}
}
}

DaveyErwin
06-18-2012, 06:37 PM
For some reason the i variable is not increasing by 1 for each loop :S

Here is the array:


r,w

Array length is 2.

Function:


//Search arrays
function array_search(array, src) {
for ( var i = 0; i < array.length; i++ ) {
alert(i);
if (array[i] == src) {
return true;
} else {
return false;
}
}
}


Because you return
before the end of
the first loop .

martynball
06-18-2012, 07:55 PM
Thanks that was the problem



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum