Cicada has two main variants of a for loop. One is a C-style for loop which fully specifies the iterator inside of parentheses. The syntax is slightly different since the iterator has to be an actual Cicada function. Here is an example:
counter :: int
for (counter = 1; return counter <= 10; counter = that + 1) print(counter, " ")
Notice that we had to define the loop variable before the loop, as either an int or a double. Anything defined inside of the parentheses will only be visible inside the iterator object.
The second type of for loop uses a prebuilt iterator whose parameters are inside of angle brackets. If there are two parameters, they are interpreted as the range of indices to loop over.
for counter in <1, 10> print(counter, " ")
One limitation: this macro for this latter for loop expects a variable name in before the ‘in’, so commands like ‘for counter::int in ...’ won’t work.
As always, we can break a loop over two lines using a ‘&’, and we can group several lines of code using parentheses beginning on the line of the for command. So we could have rewritten our code above in several different ways.
for counter in <1, 10> &
print(counter, " ")
for counter in <1, 10> (
print(counter, " ")
)
By default, a for .. in loop increments the counter by 1 each pass. To change this increment, use the step parameter after a semicolon:
for counter in <1, 10; step = 2> print(counter, " ")
If the step is negative, the loop will run backwards from the first index to the last index.
for counter in <10, 1; step = -1> print(counter, " ")
Finally, we can use the for .. in <..> iterator to loop over set elements. Now the angle brackets contain just one parameter: the set. Here is an example:
mySet :: { pi, "aString", { 1, 2 } }
el :: *
for el in <mySet> sprint(el)
Last update: July 26, 2026