-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflowanderrors.slide
More file actions
59 lines (32 loc) · 1.28 KB
/
flowanderrors.slide
File metadata and controls
59 lines (32 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Flow Control and Errors
Brian Ketelsen
me@brianketelsen.com
@bketelsen
* Flow Control and Errors
Go's control flow is very similar to C, but it has a few simplifications.
Go's if statements don't require parenthesis. They're easier to read, but you can add the parens if you want them for clarity in more complex statements.
- If Examples
cd $GOPATH/src/github.com/gophertrain/material/flowanderrors/demos/if/
go run main.go
* If Statements
It's idiomatic in go to skip the else where possible:
- Skipping Else
cd $GOPATH/src/github.com/gophertrain/material/flowanderrors/demos/skipelse/
go run main.go
* For
There's a Go joke that goes like this:
How do you spell "WHILE" in go? F O R
There is one looping construct, the "for" statement.
- For
cd $GOPATH/src/github.com/gophertrain/material/flowanderrors/demos/for/
go run main.go
* SWITCH
Go's switch statement is very powerful. Cases are evaluated top to bottom until the first match is found.
- Switch
cd $GOPATH/src/github.com/gophertrain/material/flowanderrors/demos/switch/
go run main.go
* Type Switching
One of the more common uses of the switch statement is when determining the type of an interface{} value.
- Type Switch
cd $GOPATH/src/github.com/gophertrain/material/flowanderrors/demos/typeswitch/
go run main.go