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.
Here is an example of defining an explicit function/verb containing a for loop:
Here is an example of using that verb:
The Jwiki contains a wiki page describing how to define a verb. Note the references at the bottom for more info.