# Nested for compare arrays break

**URL:** <https://forum.kirupa.com/t/nested-for-compare-arrays-break/237964>\
**Category:** Uncategorized\
**Created:** [September 5, 2007, 10:41pm UTC](https://forum.kirupa.com/t/nested-for-compare-arrays-break/237964 "2007-09-05T22:41:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![neilmmm](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@neilmmm](https://forum.kirupa.com/u/neilmmm)\
**Post date:** [September 5, 2007, 10:41pm UTC](https://forum.kirupa.com/t/nested-for-compare-arrays-break/237964/1 "2007-09-05T22:41:58Z")

</div>

i have this code to compare arrays

```auto
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

```auto
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

```auto
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
