Download A Brief J Reference

Transcript
15
atype=: 3 : 0
select. #$y
case. 0 do. 'scalar'
case. 1 do. 'vector'
case. do. 'array of dimension greater than 1'
end.
)
atype <i.3 3
scalar
atype i.3 3 3
array of dimension greater than 1
while. whilst.
The control word while. executes the loop while the control condition is true.
whilst. is the same as while, except the steps of the loop are executed once before the
control condition is tested.
sumint=: 3 : 0
k=.0
s=.0
while. k<:y do.
s=.s+k
k=.k+1
end.
s
)
sumint 10
55
for name.
Sumint=: 3 : 0
s=.0
for_k. 1+i.y
do. s=.s+k
end.
s
)
Sumint 10
55