A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
18
Task/Flow-control-structures/Go/flow-control-structures-2.go
Normal file
18
Task/Flow-control-structures/Go/flow-control-structures-2.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue