break(n)
π break(n) β Tcl Built-In Commands π
ok bestie, pull up a chair, we're talking about break π
β¨ NAME β¨
break β abort looping command π
β¨ SYNOPSIS β¨
break
β¨ DESCRIPTION β¨
so like. break is that girl you call when you're inside a loop and you simply cannot anymore π«Ά It's typically invoked inside the body of a looping command β think for, foreach, or while β and it does not do the thing politely. no ma'am.
Here's the tea: it returns a 3 (TCL_BREAK) result code, which causes a break exception to occur π And that exception is dramatic in the best way β it causes the current script to be aborted out to the innermost containing loop command, which then aborts its execution and returns normally. like, the loop just stops. no more iterations. gone. bye. β¨
ngl the "innermost containing loop" part matters β it's the closest loop that catches the exception, not some random outer one. lowkey iconic behavior.
and it's not only loops that know how to handle break exceptions, bestie. They're also handled in a few other situations:
- the
catchcommand πͺ€ - Tk event bindings ποΈ
- the outermost scripts of procedure bodies π
so it's giving "handled in multiple places" energy fr fr π
β¨ EXAMPLE β¨
wanna print a line for each of the integers from 0 to 5? say less π
for {set x 0} {$x<10} {incr x} {
if {$x > 5} {
break
}
puts "x is $x"
}
see how the loop wants to go to 10 but break said "not today" and dipped at 5? main character energy honestly π
β¨ SEE ALSO β¨
go read these too, they're all besties:
β¨ KEYWORDS β¨
abort, break, loop π«
and that's the whole page, babe π¦ this one's straight out of the Tcl manual β page break(n), Tcl Built-In Commands, brought to you by Tcl itself π no cap, that's the source, that's the version, that's the date, periodt β¨πΈ
π¦ where this page comes from
- alpine 3.22: tcl-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tcl-doc 8.6.17-r0 Β· TCL
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl-doc 8.6.17-r1 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- arch rolling: tcl 8.6.16-1 Β· TCL
- centos-stream 10: tcl-doc 1:8.6.13-4.el10 Β· TCL AND GPL-3.0-or-later WITH bison-exception-2.2 AND BSD-3-Clause
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- Copyright (c) 1993-1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms