What are the conditions for ending the cycle?

for(var i=0,k=0;i<1,k<3;iPP,kPP){
    console.log(i)
    console.log(k)
}
Feb.23,2022

this is a comma expression, and the value of the expression is determined by the expression after the last comma. (expression 1, expression 2, expression 3,., expression n) = expression n , so the loop condition is k < 3 , regardless of I .


the end judgment statement is I < 1 and k < 3 , so the ending condition is iMag3

.

clipboard.png

= correct =

tried, and the final judgment sentence is indeed k < 3 as @ sheep said, and the ending condition is k > = 3

.

ends when k > = 3, that is, whether I meets the conditions does not affect the final result, only depends on whether k meets the conditions

Menu