如何“for 循环”在 J
我尝试过,但代码不起作用。
for. T do. B end.
for_xyz. T do. B end.
在 C# 中,这相当于什么
for(int i = 0; i < 10; i++)
Console.WriteLine("Hello World!");
对于 Google 来说,对于 J 问题来说,什么是一个好的关键字?
I tried but the code wont work.
for. T do. B end.
for_xyz. T do. B end.
What would be the equivalent of this from C#
for(int i = 0; i < 10; i++)
Console.WriteLine("Hello World!");
And what's a good keyword to Google for J problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种更 J-ish 的循环方式是使用 Power
^:< /code>,这
将应用
f
10 次;首先到y
,然后到f(y)
,...:所以如果
p
是一个打印函数,例如:p =: (4) 1!:2~ ]
:一般来说,J(在某种程度上)提倡无循环代码。如果您确实需要字符串 'Hello World!' 的 10 倍例如,您可能会这样做:
A more J-ish way to loop is using Power
^:
, thiswill apply
f
10 times; first toy
, then tof(y)
, ... :So if
p
is a print function, eg:p =: (4) 1!:2~ ]
:In general J (in a way) promotes loop-less code. If you really needed 10 times the string 'Hello World!' for example, you probably would do something like:
正如控制结构部分开头所述,这些仅适用于显式定义。冒号是设置此类脚本的关键。唯一一次“为了”。 (或任何类似的单词)可以出现在由
:
的正确参数确定的脚本内,即冒号,意思是 显式。使用控制字
for.
上的链接页面查找完整示例。请注意,这些特殊符号(例如 for. 和 end.)通常出现在以单个右括号结尾的多行脚本中。如果您要使用控制字,则必须使用这种结构。以下是记录
for.
结构的词典页面上给出的第一个示例 (http://jsoftware.com/help/dictionary/cfor.htm):一旦您在其中安排了控制字某种结构,它们在执行脚本时生效。在此示例中,当动词
f0
接收一个整数作为其唯一(右侧)参数(在脚本中称为y
)时,它会生成相同的整数。它迭代 for 循环以得出该数字。As noted at the beginning of the Control Structures section, these only apply within Explicit definition. The colon is the key for setting up such a script. The only time 'for.' (or any similar word) can occur is within a script determined by the right parameter to
:
, i.e. colon, meaning Explicit.Use the link on the control-word
for.
on that page to find complete samples. Notice that these special symbols (such as for. and end.) normally occur in multi-line scripts that end with a single lone right-paren. That sort of structure is what you must use if you're to use control words.Here is the first of the examples given on the Dictionary page documenting the
for.
structure (http://jsoftware.com/help/dictionary/cfor.htm):Once you have arranged control words inside this sort of structure, they take effect when the script is executed. In this example, when the verb
f0
receives an integer as its only (right) parameter (referred to asy
in the script) it results in the same integer. It iterates through the for loop to arrive at that number.