RosettaCodeData/Task/Flow-control-structures/Go/flow-control-structures-2.go
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

18 lines
458 B
Go

import "os"
func processFile() {
f, err := os.Open("file")
if err != nil {
// (probably do something with the error)
return // no need to close file, it didn't open
}
defer f.Close() // file is open. no matter what, close it on return
var lucky bool
// some processing
if (lucky) {
// f.Close() will get called here
return
}
// more processing
// f.Close() will get called here too
}