문제

나는 시도했지만 코드는 일하지 않을 것이다.

for.     T do. B end.
for_xyz. T do. B end.
.

C # 에서 이에 대한 이와 동일 할 것입니다.

for(int i = 0; i < 10; i++)
    Console.WriteLine("Hello World!");
.

및 J 문제에 대한 Google에 좋은 키워드는 무엇입니까?

도움이 되었습니까?

해결책

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):

f0=. 3 : 0
 s=. 0
 for. i. y do. s=. >:s end.
)

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 as y in the script) it results in the same integer. It iterates through the for loop to arrive at that number.

다른 팁

A more J-ish way to loop is using Power ^:, this

f^:10 y

will apply f 10 times; first to y, then to f(y), ... :

f(f(f(f(f(f(f(f(f(f(y))))))))))

So if p is a print function, eg: p =: (4) 1!:2~ ]:

(p^:10) 'Hello World!'
Hello World!Hello World!...

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:

10 12 $ 'Hello World!'
Hello World!
Hello World!
Hello World!
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top