FOR 循环中的逗号运算符是如何工作的?
谁能解释一下 FOR 语句中的逗号运算符吗?
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!!
}
}
另外,最后一个语句“a++”似乎丢失了。我从来没有见过这样的事情。这意味着什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
逗号只是为多个声明添加分隔符。换句话说,您的
for
循环将a
设置为等于x
,并将e
设置为等于>y
。至于缺少increment语句,缺少它只是意味着for循环不会显式增加任何变量。
The comma just adds separation for multiple declarations. In other words, your
for
loop is settinga
equal tox
, as well ase
equal toy
.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 comma 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 complete.
C、C++ 和 JavaScript(也许是 C#)中的逗号运算符的工作方式如下:
因此,在循环中,它初始化两个整数值,
a
和e
,它们是分别设置为x
和y
。没有增量,因为循环正在与 c 进行比较,c 可能是在循环内的某个位置设置的。The comma operator in C, C++, and JavaScript (maybe C#) works like this:
So, in your loop, it initializes two integer values,
a
ande
, which are set tox
andy
, respectively. There is no increment because the loop is comparing againstc
, which is probably set somewhere inside the loop.