loop problem
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;
}