break(3tcl)

πŸ’… break(3tcl) β€” Tcl Built-In Commands

okay bestie, welcome to the break page, she's short but she is powerful, and she lives in the Tcl Built-In Commands manual. let's go πŸŽ€


✨ NAME ✨

break β€” abort looping command. literally just "stop the loop", that's her whole job, and she ate πŸ’…


🌸 SYNOPSIS 🌸

break

no args, no flags, no options, she takes nothing and she gives everything 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the vibe is: you call break inside the body of a looping command β€” think for, or foreach, or while, the usual suspects. πŸ’–

when you do, it returns a 3 (TCL_BREAK) result code, which causes a break exception to occur. and that exception does the thing: it causes the current script to be aborted out to the innermost containing loop command, and that loop then aborts its execution and returns normally. like, she just dips, no drama, no error message, the loop is done, moving on πŸ‘‘

and not me telling you this but β€” break exceptions are also handled in a few other situations, bestie, namely:

  • the catch command
  • Tk event bindings
  • the outermost scripts of procedure bodies

so it's not only loops, iykyk. the more you know ✨


πŸ“ EXAMPLE πŸ“

print a line for each of the integers from 0 to 5:

for {set x 0} {$x<10} {incr x} {
    if {$x > 5} {
        break
    }
    puts "x is $x"
}

see how the loop says it'll go to 10 but break is like "no babe, we're done at 5"? main character energy fr fr πŸ’…


🌈 SEE ALSO 🌈


πŸ‘‘ KEYWORDS πŸ‘‘

abort, break, loop


ngl this is the whole page, there's no bugs section, no warnings, nothing scary. she's simple, she's iconic, she's break. periodt. πŸ’œ

that's a wrap bestie!! this was the break(3tcl) page from Tcl, version and date stamped on the original footer as Tcl / break(3tcl) β€” sending you love and a clean loop exit πŸŽ€βœ¨πŸ¦‹πŸ’–