Skip to main content
May 3, 2011
Question

loop problem

  • May 3, 2011
  • 2 replies
  • 355 views

Hello,

I have some code, which I haven't written very well, I know... I didn't understand (before) that the function was stopped once it returned true or false... how can I optimize this to give more than one response ? At present I only receive addVScore as true or addHScore as true and never both, even if that is the case. Thanks in advance :-

for(i = 0; i < totalGridRefArray.length; i++) {

     var checkTile = totalGridRefArray.gridRef;

     var checkTileValue = totalGridRefArray.tileValue;

     var checkTileColor = totalGridRefArray.tileColor;

      if(checkTile == t1) {

          addVScore = true;

          trace("Tile present above", t1);

     }

     if(checkTile == t2 && t2 != 12 && t2 != 24 && t2 != 36 && t2 != 48 && t2 != 60 && t2 != 72 && t2 != 84 && t2 != 96 && t2 != 108 && t2 != 120) {                  addHScore = true;

          trace("Tile present left", t2);

     }

     if(checkTile == t3 && t3 != 13 && t3 != 25 && t3 != 37 && t3 != 49 && t3 != 61 && t3 != 73 && t3 != 85 && t3 != 97 && t3 != 109 && t3 != 121) {

          addHScore = true;

          trace("Tile present to right", t3);

     }

     if(checkTile == t4) {

          addVScore = true;

          trace("Tile present below", t4);

     }

     if(checkTile == t1) {

          if(theColor == checkTileColor) {

               return false;

          }

          return true;

          } else if(checkTile == t2 && t2 != 12 && t2 != 24 && t2 != 36 && t2 != 48 && t2 != 60 && t2 != 72 && t2 != 84 && t2 != 96 && t2 != 108 && t2 != 120) {

               if(theColor == checkTileColor) {

                    return false;

               }

               return true;

          } else if(checkTile == t3 && t3 != 13 && t3 != 25 && t3 != 37 && t3 != 49 && t3 != 61 && t3 != 73 && t3 != 85 && t3 != 97 && t3 != 109 && t3 != 121) {

               if(theColor == checkTileColor) {

                    return false;

               }

               return true;

          } else if(checkTile == t4) {

               if(theColor == checkTileColor) {

                    return false;

               }

               return true;

          }

     }

     return false;

}

This topic has been closed for replies.

2 replies

May 3, 2011

I'm going to repost this.

May 3, 2011

forgot the variables sorry :-

var t1 = gridPosition - 12;
var t2 = gridPosition - 1;
var t3 = gridPosition + 1;
var t4 = gridPosition + 12;