Cicada ---> Online Help Docs ---> Cicada scripting ---> Loops and if blocks

for

Cicada’s for loop is simpler and offers less control than C’s. Here is an example showing the syntax.


    counter :: int
    for counter in <1, 10-counter> print(counter, " ")
   

Notice that we had to define the loop variable before the loop, as either an int or a double. The loop itself will print the numbers 1 through 5; when counter reaches 6 it will be greater than 10-counter and the loop will stop.

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.


    counter :: int
   
    for counter in <1, 10-counter> &
       print(counter, " ")
   
    for counter in <1, 10-counter> (
       print(counter)
       print(" ")
    )
   

Unlike Cicada’s predecessor (Yazoo scripting language) there is no step argument to control the increment of the counter variable. This is due to limitations of the new compiler. Of course there are a number of ways around this, one of which is to change the loop to a while loop and do the step manually. The loop in our example is equivalent to:


    counter := 1
    while counter <= 10-counter do (
       print(counter, " ")
       counter = that + 1
    )
   


Prev: while do and loop until    Next: backfor


Last update: May 8, 2024