Loops/Do-while: Difference between revisions
Content deleted Content added
Line 1,601: | Line 1,601: | ||
J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way: |
J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way: |
||
,. |
<syntaxhighlight lang=J> ,.([^:(0=6|])>:)^:a: 0 |
||
0 |
|||
1 |
|||
2 |
|||
3 |
|||
4 |
|||
5 |
|||
</syntaxhighlight> |
|||
This could also be accomplished using [[j:Vocabulary/zcapco|Z:]] to provide early termination from a [[j:Vocabulary/fcap|fold]]: |
|||
<syntaxhighlight lang=J> 0#]F.(>: [ echo [ _2 Z: * * 0=6|]) 0 |
|||
0 |
|||
1 |
|||
2 |
|||
3 |
|||
4 |
|||
5 |
|||
</syntaxhighlight> |
|||
J does support loops for those times they can't be avoided (just like many languages support gotos for those time they can't be avoided). |
J does support loops for those times they can't be avoided (just like many languages support gotos for those time they can't be avoided). |