Can I place two conditions / increments within the same loop?

2

I basically want to do this

for (j = parametro, int k=0; j < parametro + 3, k<3; j++, k++) {
    previsoes[i] += valores[j] * pesos[k] ;
}
    
asked by anonymous 14.11.2017 / 16:34

1 answer

9

It can.

Note that after the first statement you do not have to specify the type. The increment is correct. I took advantage of and added an example of how to put "two conditions".

So:

class Main {
    public static void main(String[] args) {
        for (int i = 0, k = 0; i < 10 && k < 3; i++, k++) {
            System.out.println(i);
            System.out.println(k);
        }
    }
}

See working at Repl.it

    
14.11.2017 / 16:40