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

break

There is no break statement in Cicada. But there is a way to jerry-rig something that does pretty much the same. The trick is to put braces -- with no code marker or semicolon -- around the code we eventually want to escape from. Within those braces, a return statement will simply escape from the bracketed code and continue with what follows. For example:


    {
       for counter in <1, 10> (
           print(counter)
           if input() == "q" then return   )
    }
    print("finished with counter = ", counter)
   

This works because the braces define a new composite variable, and the code inside the braces is actually running inside of this variable. Be wary of pitfalls: if we define a member, that member will be inside of this variable, which was probably not intended. ‘this’ now refers to this newly-defined variable, while ‘parent’ now refers to the location outside the braces. Also, if this is all inside of a function definition, we can’t return from the function until we leave the braces block. On the upside, we have a lot of latitude in choosing where to break from and to: it doesn’t have to escape from a loop, and we can jump out of several nested loops at once unlike in C where we always fall back to the enclosing loop.


Prev: backfor    Next: Sets


Last update: November 12, 2025