samedi 27 décembre 2014

If clause with multiple conditions

I seem to be lost or just seem to be confused. To simplify the problem: I want to check whether each in an array holds true and if and only if all are true it should return a specific value.



var trueArray=[true,true,true,true];


As in my code, the array can have length up to 100 elements, I can't simply check for every element but need a for loop.



for(var i=0;i<trueArray.length;i++){
if(trueArray[i]===true){
//do something
}
}


However, the above code does something on each step of the loop but I only want it to do something once every condition held true and not inbetween. Can't think of the solution at the moment


Aucun commentaire:

Enregistrer un commentaire