Nested For Each X element in Array

Get help using Construct 2

Post » Fri Jul 05, 2013 9:56 pm

I'm trying to recreate the code below in Construct 2. I think I have most of it correct, but the stop loop doesn't seem to work.

var array1 = new Array("a" , "g" , "e" , "j" , "a");
var array2 = new Array("b" , "a" , "c");          
for each (var letter in array2) {
for (var i=0; i < array1.length ; i++) {
    if (letter == array1(i)){
        array1(i) = -1;
        break;
     }
}
trace(array1);
// OUTPUT: is -1,g,e,j,a

When the loop finds the first letter 'a' it changes it to '-1', but stops and doesn't change the last 'a'. In Construct the output is -1,g,e,j,-1. The only thing I can think of is that I'm not implementing the stop loop properly.

          
B
3
Posts: 5
Reputation: 185

Return to How do I....?

Who is online

Users browsing this forum: jul, terrimac001 and 4 guests