Nested For Each X element in Array

0 favourites
  • 1 posts
From the Asset Store
🙌 Element Magic Hit Sound Pack comes with 805 high-quality sound effect
  • 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;





    // 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="" border="0" />

  • Try Construct 3

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

    Try 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)