Expand/Shrink

For in Statement

In many cases the following variant of the for statement permits noticeably neater code, for instance:
    for i,e in s do
is equivalent to/shorthand for
    for i=1 to length(s) do
        object e = s[i]
The control variable, i, can be omitted, in which case an anonymous temporary variable is used (which may make debugging harder).
The default starting point of 1 can be overidden with a from clause, ditto end point of length(s) using a to clause, which can sometimes save an unecessary slice operation.
The element, e, is automatically declared as object type1 and scoped to the loop if it does not already exist.2
The target sequence, s, can be any legal expression or literal, with of course non-sequences triggering the usual "length of an atom is not defined" error at run time. Other valid forms include but are not limited to:
    for e in s do
    for i,e in s[k] do
    for e in {1,"two",{3,4.5}} do
    for word in {"one","two","three"} do
    for word in filter(unix_dict(),twovowels) do
    for ch in "word" do
    for i in tagstart(5,5,5) do -- {5,10,15,20,25}
Technicalia
Expand/Shrink