Loop structures: Difference between revisions
→Frink
(→Forth) |
(→Frink) |
||
Line 382:
===For Loop===
A <CODE>for</CODE> loop is really a <CODE>foreach</CODE> loop that can work with range operators or iterate through various data structures. The <CODE>to</CODE> operator creates an enumerating expression that lazily steps through its range.
<
for i = 1 to 1000000
{
println[i]
}
</syntaxhighlight>
The <CODE>to</CODE> operator can be combined with a <CODE>step</CODE> statement:
<
for i = 1 to 1000000 step 3
println[i]
</syntaxhighlight>
As a <CODE>foreach</CODE> statement. The <CODE>for</CODE> construct can iterate over the elements of an array, set, dictionary, or enumerating expression.
<
for i = [2,3,7,9]
println[i]
</syntaxhighlight>
===Do...While Loop===
<
i=0
do
Line 408 ⟶ 409:
i = i+1
} while i<1000
</syntaxhighlight>
==[[Groovy]]==
|