mercredi 25 novembre 2015

How to reduce "if statement" conditions? [reduce the conditions inside the if statement]

after days of hard thinking i choose to ask that question. I have if statement with multiple conditions:

//var current is array of arrays of integers
if((current[rot][0] + x)<blocks.length 
    && (current[rot][1] + x)<blocks.length 
    && (current[rot][2] + x)<blocks.length 
    && (current[rot][3] + x)<blocks.length
    && !$(blocks[current[rot][0]+x]).hasClass("blockLand") 
    && !$(blocks[current[rot][1]+x]).hasClass("blockLand")
    && !$(blocks[current[rot][2]+x]).hasClass("blockLand")
    && !$(blocks[current[rot][3]+x]).hasClass("blockLand"))
    {
    //something to happen here ONCE!
    }

Because i want something inside to happen just once i think i cant use for loop. So my question is: is there a possible way to reduce the conditions number? and how?

P.S.: Yes i figured out that i can use flag (true/false) inside and do my stuff outside this if, in another if - but i think that not always gonna work, because for every loop the flag will be different.

Aucun commentaire:

Enregistrer un commentaire