0 Favourites

Nested For Each X element in Array

  • 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.

              <img src="http://assets.universityalliance.com/construct/screenCap.jpg" border="0" />

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
101 37,415
imothep85's avatar
imothep85
Unread hot topic
0 Favourites
Fill Array with Sprites
48 2,319
Congrats2u's avatar
Congrats2u
Unread hot topic
0 Favourites
How do i use arrays?
44 6,458
HapaxHypatia's avatar
HapaxHypatia