Is it possible to put an OR in the stop condition of FOR?

2

Can two conditions be set to stop a for ? In my example I'm trying to do this:

function criacaoParidade(entrada) {
    entrada = Array.from(entrada);
    func = positionBit(entrada);

    tam = entrada.length;
    var dic = {};

    for (let index = 0; (index < tam || paridade > tam); index++) {
        var paridade = func[index];
        console.log(paridade)
    }
    
asked by anonymous 28.08.2018 / 07:06

1 answer

1

Two conditions can not, only one is possible that is the middle, as you already know. But you can use || or other operators, several times. It will still have a condition, but the expression may be much more complex, what matters is that in the end it will result in a boolean. Then you can have multiple comparative expressions bound by relational operators.

But in your case it does not make sense, it is impossible to index be less than tam , after all it was declared 0 just before and tam is a size that can not be less than 0 . It could make it simple like this:

for (let index = 0; index < entrada.length; index++)

It does not make sense, and usually worse, to get the size off the loop. There are other weird and probably wrong things in this code.

    
28.08.2018 / 13:56