Loops/For with a specified step: Difference between revisions

(→‎{{header|Groovy}}: new solution)
Line 234:
fmt.Printf("%d\n", i)
}</lang>
 
=={{header|Groovy}}==
"for" loop:
<lang groovy>for(i in (2..9).step(2)) {
print "${i} "
}
println "Who do we appreciate?"</lang>
 
"each() method:
Though technically not a loop, most Groovy programmers would use the slightly more terse "each()" method on the collection itself, instead of a "for" loop.
<lang groovy>(2..9).step(2).each {
print "${it} "
}
println "Who do we appreciate?"</lang>
 
Output:
<pre>2 4 6 8 Who do we appreciate?</pre>
Go Team!
 
=={{header|Haskell}}==
Anonymous user