i have this code to compare arrays
var array1:Array = new Array([1, 2, 3, 4, 5, 6, 7, 8, 9], [7, 8, 3, 4, 5, 6, 1, 2, 3]);
var array2:Array = new Array([7, 7, 1, 2, 3, 4, 5, 8, 2]);
for (j=0; j<array1.length; j++) {
for (i=0; i<array1[0].length; i++) {
trace(array1[j]*+" "+array2[0]*);
if (array1[j]* == array2[0]*) {
trace("match");
}
}
}
which, as it stands, finds two matches. Fine.
However, if there is a match i want to stop both for loops and run a function
if i put a break here
var array1:Array = new Array([1, 2, 3, 4, 5, 6, 7, 8, 9], [7, 8, 3, 4, 5, 6, 1, 2, 3]);
var array2:Array = new Array([7, 7, 1, 2, 3, 4, 5, 8, 2]);
for (j=0; j<array1.length; j++) {
for (i=0; i<array1[0].length; i++) {
trace(array1[j]*+" "+array2[0]*);
if (array1[j]* == array2[0]*) {
trace("match");
break;
}
}
}
it only breaks one for loop, and just begins checking the next element of array1.
secondly if there were no matches at all, anywhere, i want to run a function
an else here
for (j=0; j<array1.length; j++) {
for (i=0; i<array1[0].length; i++) {
trace(array1[j]*+" "+array2[0]*);
if (array1[j]* == array2[0]*) {
trace("match");
}else{
trace ("no match");
}
}
}
obviously runs an else on every non match!!!
many thanks