[英]J Programming Beginners Loop
Could someone kindly explain the control structure in J (specifically For and While loops)? 有人可以解释一下J中的控制结构(特别是For和While循环)吗? Let's say I have a=:1 and b=:10, and I want to add '1' to 'a' using For/While loops till a < b.
假设我有a =:1和b =:10,并且我想使用For / While循环将'1'添加到'a',直到a <b。
So, usually it would be something like (in other languages) 因此,通常情况会是这样(用其他语言)
for i= 1 to b
a=a+1
next i
or 要么
while a<=b
a=a+1
end
Help please. 请帮助。 I know it's simple, but I can't figure out how to do this in loops.
我知道这很简单,但是我不知道如何循环执行。
Also, I read up on something called "explicits". 另外,我阅读了一些称为“显式”的内容。 For example:
例如:
foo=: 3 : 0
if. 1 do. wdinfo 'success' end.
)
What would the 3 and 0 denote? 3和0代表什么?
Control structures must be used within an explicit definition . 控制结构必须在显式定义内使用。 The explicit definition link will explain what the "3" and "0" signify, but note that the following are equivalent.
显式定义链接将解释“ 3”和“ 0”的含义,但请注意,以下内容是等效的。
myfunction=: 3 : 0
NB. define function/verb here
)
myfunction=: verb define
NB. define function/verb here
)
Here is an example of defining an explicit function/verb containing a for loop: 这是定义包含for循环的显式函数/动词的示例:
for_eg=: verb define
a=. 3
b=. 8
for. i.b do.
a=. a + 1
end.
a
)
Here is an example of using that verb: 这是使用该动词的示例:
for_eg ''
11
The Jwiki contains a wiki page describing how to define a verb. Jwiki包含描述如何定义动词的Wiki页面 。 Note the references at the bottom for more info.
请注意底部的参考以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.