1
Code 1:
var x = 1;
for( ; x<6 ; x+=2 ){
x=x*x;
}
console.log(x);
In the above code even if the condition is false the incrementing part is last executed.
Code 2:
var x = 0;
for( ; x<8 ; x++ ){}
console.log(x);
for( ; x>4 ; x-=2 ){}
console.log(x);
In the above code even if the condition is false the incrementing part is not executed.
Why does this happen or am I making a mistake?
Can do table test? If yes, try to do in both codes. I particularly did not understand the questions.
– Woss
@Lucas Costa, it is simple, in the first code even x being greater than 6 the part of the increment of the for(;(this part here)) it is executed, that is, there is the increment of x and it becomes 11 at the end. In the second code when x < 8 the increment part of x is not executed, in the same way with the second is, that is, when x is 8 the part x++ is not executed, so much so that the value of x is 8 at the end of the code. The question is: why is logic different for both?
– chmod777
The debugger is your friend.
– Oralista de Sistemas