L/loop keyword



There are 4 forms of loops in 11l.


1. The infinite loop.


L
   print("\a")
   sleep(1)


2. A "while" loop.


L <expression>
   ...

Keep executing a loop body as long the given expression is true (1B).

Note: if
<expression>
is just a single identifier, like
L ok {...}
, then please write this:
L ok == 1B {...}
.


3. Loop a particular number of times.


L <number>
   ...

Example:
L 3
   print("ABC")
will print "ABC" 3 times.

Note: only integer literals/constants are considered so far as
<number>
{}.


4. A "for in" loop.


L(variable) <iterable>
   ...

Examples:
L(x) 1..10 {print(x)}
will print
1
through
10
.
L(c) "str" {print(c)}
will print
"s"
,
"t"
and
"r"
.
L(n) [9,7] {print(n)}
will print
9
and
7
.
L(k, v) [‘k’ = 1] {print(k‘=’v)}
will print
k=1
.


L/loop subkeywords



The
L.break
/
loop.break
statement terminates the current loop.
By default
L.break
/
loop.break
will apply to innermost loop. In a situation where you would like to a break for one of the outer loops, you can specify which loop the break statement applies to:
L(y) 0..10
   L(x) 0..10
      I a[y][x] == 1
         L(y).break
Or you can use
^L.break
,
^^L.break
, etc.


The
L.continue
/
loop.continue
statement terminates execution of the statements in the current iteration of the current loop, and continues execution of the loop with the next iteration.


Statements under
L.was_no_break
/
loop.was_no_break
are executed only when loop was successfully finished without
L.break
/
loop.break
(just like else in Python):
L(test) tests
   I !test.ok()
      L.break

   L.was_no_break
      print(‘All tests are ok!’)


L.index
/
loop.index
can be used to get the index of the current iteration of loop.


L.next
/
loop.next
support now is limited to check if there is a next element in iterating container or current element is the last one.
L.prev
/
loop.prev
is not supported now.