Ive written a script to loop through a couple of unparalleled arrays a loop within a loop, Now im trying to find out if using break
is all that's needed to exit and then continue over again.
What eles can you see or know to improve this?
var arr_vals = ["74","f4e3","22","r31","17","hundernds"]; // could have 500+ items
var arr_items = ["r31","22","65","100"]; // could have 50 items
var c = arr_items.length;
var arr_vals_len = arr_vals.length;
for ( var i = 0; i < c; i++ ) {
var xid = arr_items[i];
for (var j = 0; j < arr_vals_len; j++ ){
if(arr_vals[j] === xid){
// match !
break;
}
}
break
will break out of the inner loop but not the outer one, so it will continue with the next iteration of the outer loop. Is that what you're asking? Also, I think you meanvar j
rather thanvar r
. – seand Apr 23 '12 at 21:01