-
Notifications
You must be signed in to change notification settings - Fork 10
Loops
The basic precondition loop is declared using the while
keyword:
var a = 0
while a < 10 do
println "{0}..." a
a = a + 1
To iterate over a list of values one can use the for
loop:
let data = new [1; 2; 3; 4; 5]
for i in data do
print "the value is {0}!" i
The same keyword can also be used to define a classic index loop:
for i in 1 .. 5 do
print i
If the second boundary of the loop is smaller than the first, the index will gradually decrement instead of incrementing. The step is always equal to 1. To use a different step one might use the to
extension method to construct a custom range of values.
Unlike many languages, LENS does not have break
or continue
keywords. There is no way to exit a loop prematurely or skip an iteration.
The loop can be used as an expression if passed to a function, placed at the right side of an assignment statement or as the last statement of a function. The result is the value of the loop's last line. If the loop has not run a single iteration, the default
value is returned.