Can anyone please explain the ma 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?
Can anyone please explain the ma 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?
Share Improve this question edited Jun 8, 2022 at 18:09 Jonathan Leffler 756k145 gold badges951 silver badges1.3k bronze badges asked Jan 23, 2012 at 2:37 user1015551user1015551 1973 silver badges20 bronze badges 5- @amnotiam what is it then? I can properly tag it if needed. – Richard J. Ross III Commented Jan 23, 2012 at 2:48
- Not sure. The ma will work the same in JS, but JS doesn't have statically typed variables. – user1106925 Commented Jan 23, 2012 at 2:49
- it is js, I know it for a fact ;) – user1015551 Commented Jan 23, 2012 at 2:54
-
@user1015551: JS doesn't have
int
. – user1106925 Commented Jan 23, 2012 at 2:59 - 2 ahh damn, my bad, I was rewriting it in C# and copied the wrong code, lol – user1015551 Commented Jan 23, 2012 at 3:00
3 Answers
Reset to default 2The ma 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.
The ma just allows you to initialise more than one variable at the start of the loop. And the missing increment operator means that there must be some script inside the loop that will eventually satisfy the termination condition, otherwise the loop would never plete.
The ma operator in C, C++, and JavaScript (maybe C#) works like this:
ma_operator(statement_1, statement_2) {
execute statement_1
return statement_2
}
So, in your loop, it initializes two integer values, a
and e
, which are set to x
and y
, respectively. There is no increment because the loop is paring against c
, which is probably set somewhere inside the loop.