Loops/Break: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Made the Kotlin example not use Java.)
(→‎{{header|J}}: show a fold single example)
Line 1,814: Line 1,814:


=={{header|J}}==
=={{header|J}}==
In recent versions of J, [[j:Vocabulary/zcapco|Z:]] can be used to provide early termination from a [[j:Vocabulary/fcap|fold]]. For example:

<syntaxhighlight lang=J> ]F.(( _2 Z: 10&= [ echo)@(?@20))''
15
6
5
10

]F.(( _2 Z: 10&= [ echo)@(?@20))''
14
9
3
8
19
14
5
13
8
1
19
2
10

</syntaxhighlight>

But other mechanisms are also supported:

<syntaxhighlight lang="j">loopexample=: {{
<syntaxhighlight lang="j">loopexample=: {{
while. do.
while. do.