[英]Can someone explain me the Syntax of a loop like “for (;;)”
Can someone explain me the Syntax of a for-loop
like "for (;;)"
what i need to know is whether the header of a for-loop
like "for (;;)"
is having empty-statements
or not.有人可以向我解释像"for (;;)"
这样的for-loop
的语法吗?我需要知道的是像"for (;;)"
这样的for-loop
的header是否empty-statements
。
I searched the ECMAScript specification about what will happen if all the optional expressions within the for-loop's
header is skipped like for (;;)
in the specification but i still didnt find about it我在ECMAScript 规范中搜索了如果for-loop's
header 中的所有可选表达式都像规范中的for (;;)
一样被跳过会发生什么,但我仍然没有找到它
can someone explain me about this even the specification haven't mentioned that a for-loop
like for (;;)
loops/runs infinite times即使规范没有提到像for (;;)
这样的 for for-loop
循环/运行无限次,有人可以解释一下吗
and i need to know one last thing why people call the header of a for-loop
is having Expression's
i see that the syntax of a for loop allows us to write declarations like var i = 0
in the header of the for-loop
and i see the for-loops
syntax allows us to write semicolons;
我需要知道最后一件事,为什么人们将for-loop
的 header 称为Expression's
,我看到 for 循环的语法允许我们在 for 循环in the header of the for-loop
和 i 中编写像var i = 0
这样的声明看到for-loops
语法允许我们写semicolons;
in its header only statements require semicolons
does that mean all the syntax within the for-loop's
header is having Statements
在其 header 中,只有语句需要semicolons
,这是否意味着for-loop's
header 中的所有语法都有Statements
In a standard for loop definition, it would go as follows:在循环定义的标准中,它将 go 如下:
for (var i = 0; i < 5; i++)
{
//Do something here
}
You have your statement being defining i as 0 ( var i = 0
).您的声明将 i 定义为 0 ( var i = 0
)。 Then, there is the condition/expression that the for loop checks each time as it runs, which in this example checks that i is less than 5 ( i < 5
).然后,for 循环每次运行时都会检查条件/表达式,在此示例中检查 i 是否小于 5 ( i < 5
)。
So, to address the first part of your question, when you define a for loop as for(;;)
, you are simply defining a loop with no condition that must be met.因此,为了解决问题的第一部分,当您将 for 循环定义为for(;;)
时,您只是定义了一个没有必须满足条件的循环。 Therefore, it continues to run/loop forever.因此,它会永远继续运行/循环。 This can be done because all parts of the for loop definition are optional.可以这样做是因为 for 循环定义的所有部分都是可选的。 So, there are no " empty-statements
".因此,没有“ empty-statements
”。 It is simply defining the for loop without the optional arguments.它只是定义了没有可选 arguments 的 for 循环。 We fill it in with semicolons instead in order to represent the transition between the empty arguments.我们用分号填充它,以表示空 arguments 之间的转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.