Loops/For: Difference between revisions
→{{header|APL}}: Improve nested version portability; add tradfn version with :for
(Simple for loop in Rapira) |
(→{{header|APL}}: Improve nested version portability; add tradfn version with :for) |
||
Line 369:
=={{header|APL}}==
<lang APL>stars ← {
<lang APL>stars ← { ⍵ 1 ⍴ { {'*'} ¨ ⍳⍵} ¨ ⍳⍵ }</lang>
Additionally, Dyalog and some other dialects support the more traditional structured programming controls inside a named function definition (tradfn):
{{works with|Dyalog APL}}
<lang APL>∇result ← stars count; i; j; vec
vec ← ⍬
:for i :in ⍳ count
vec ,← ⊂''
:for j :in ⍳ i
vec[i],←'*'
:endfor
:endfor
result ← count 1 ⍴ vec
∇</lang>
{{Out}}
The result of all three implementations of `stars` is a column vector, which is displayed like this:
<pre>
*
**
***
|