break(n)

πŸ“¦
version 9.0.3 Β· 2 versions
  • 9.0.3 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0 (latest)
  • 8.6.10 Β· centos-stream 9
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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 catch command πŸͺ€
  • 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