J编程初学者循环 [英] J Programming Beginners Loop
问题描述
假设我有a =:1和b =:10,并且我想使用For / While循环将'1'加到'a',直到< b。
所以,通常情况下会是这样的(用其他语言)
for i = 1 to b
a = a + 1
next i
或
while a <= b
a = a + 1
end
请帮忙。我知道这很简单,但我不知道如何在循环中做到这一点。
另外,我读了一些叫做explicits的东西。例如:
foo =:3:0
if。 1做。 wdinfo'成功'结束。
)
3和0表示什么?
控制结构必须在显式定义中使用。
明确的定义链接将解释3和0是什么意思,但是请注意以下内容是相同的。
myfunction =:3:0
NB。在这里定义函数/动词
)
myfunction =:动词define
NB。在这里定义函数/动词
)
下面是一个定义显式函数/动词包含一个for循环:
for_eg =:动词define
a =。 3
b =。 8
。我做了。
a =。 a + 1
结束。
这是一个使用这个动词的例子:
for_eg''
11
Jwiki包含一个 wiki页面,介绍如何定义一个动词。请注意底部的参考资料以获取更多信息。
Could someone kindly explain the control structure in J (specifically For and While loops)?
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.
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?
解决方案 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.
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_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. Note the references at the bottom for more info.
这篇关于J编程初学者循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!