TIL
Named break statement in Go
- 1 minutes read - 71 wordsI came across this piece of code from The Go Programming Language book.
loop:
for {
select {
case size, ok := <-fileSizes:
if !ok {
break loop // fileSizes was closed
}
nfiles++
nbytes += size
case <-tick:
printDiskUsage(nfiles, nbytes)
}
}
The complete program is available in Github
Named break
statement allows to break perhaps multiple control statements. In this example, break loop
breaks the select
and for
statement.