Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comma operator in FOR loop, how does that work?

Can anyone please explain the comma operator in FOR statement?

function funct_1(c){
    for (var a = x, e = y; 0 < c; ){ 
         var p = c/2;
         var c = c/10; // wtf, it is already defined as function argument!!
    }
}

Also, the last statement like "a++" seems to be missing. I have never seen anything like this. what does that mean?

like image 440
user1015551 Avatar asked Oct 20 '25 01:10

user1015551


1 Answers

The comma just adds separation for multiple declarations. In other words, your for loop is setting a equal to x, as well as e equal to y.

As for the lack of the increment statement, the fact that it is missing just means that the for loop won't explicitly increment any variable.