Loops/Continue: Difference between revisions

→‎{{header|Wren}}: Updated to v0.4.0
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
(→‎{{header|Wren}}: Updated to v0.4.0)
Line 2,305:
 
=={{header|Wren}}==
WrenFrom doesv0.4.0 notWren currently havehas a ''continue'' keyword but,which dependingworks onin the circumstances, I can think of four ways in which to work around itsexpected absencefashion.
<lang ecmascript>//for Invert(i thein condition1..10) {
// OK for simple cases.
for (i in 1..10) {
System.write(i)
if (i%5 != 0) {
System.write(", ")
} else {
System.print()
}
}
 
System.print()
 
// Use a flag to indicate whether to continue or not.
// OK as a more general approach.
for (i in 1..10) {
System.write(i)
var cont = false
if (i%5 == 0) {
System.print()
cont = truecontinue
}
if (!cont) System.write(", ")
}
 
System.print()</lang>
 
// Break out of an inner infinite loop.
// Not good if you also need to use 'break' normally.
for (i in 1..10) {
while (true) {
System.write(i)
if (i%5 == 0) {
System.print()
break
}
System.write(", ")
break
}
}
 
System.print()
 
// Return from an inner closure.
// Heavy handed, other methods usually preferable.
for (i in 1..10) {
Fn.new {
System.write(i)
if (i%5 == 0) {
System.print()
return
}
System.write(", ")
}.call()
}</lang>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
 
1, 2, 3, 4, 5
6, 7, 8, 9, 10
 
1, 2, 3, 4, 5
6, 7, 8, 9, 10
 
1, 2, 3, 4, 5
6, 7, 8, 9, 10
9,482

edits