This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path05-control-structures.slide
More file actions
93 lines (54 loc) · 1.96 KB
/
05-control-structures.slide
File metadata and controls
93 lines (54 loc) · 1.96 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Go Control Structures
22 Feb 2017
Tags: edmonton-go, golang, workshop, workshop-one, control-structures
Nicholas Boers
MacEwan University
* if
.play -edit 05-control-structures/if.go /START OMIT/,/END OMIT/
- *No* parentheses when they're redundant: `(` `)`
- *Required* curly braces: `{` `}`
* Scope
.play -edit 05-control-structures/if.go /START OMIT/,/END OMIT/
- Lexically scoped using blocks
- Curly braces delimit blocks
* if/else
.play -edit 05-control-structures/ifelse.go /START OMIT/,/END OMIT/
- Nothing to see here... (yawn)
* if/else if/...
.play -edit 05-control-structures/ifelseif.go /START OMIT/,/END OMIT/
- `else if` is handled like C, rather than like Python
* if with a simple statement
- Something *new*!
.play -edit 05-control-structures/simpstmt.go /START OMIT/,/END OMIT/
- A note on scope...
* for
Go provides *three* forms of `for` statement:
- First form: C-style `for`
- Second form: C-style `while`
- Third form: Python-style `for` (Covered after lunch)
We'll look at each separately...
* for: C-style `for`
.play -edit 05-control-structures/for.go /START OMIT/,/END OMIT/
- *No* parentheses
- *Required* curly braces: `{` `}`
- Otherwise, the usual three parts: initialization, condition, and update
* for: C-style `while'
- Something *different*!
.play -edit 05-control-structures/forwhile.go /START OMIT/,/END OMIT/
- `while` doesn't exist in Go
- `for` provides the same functionality
* for: infinite loops
.play -edit 05-control-structures/forinf.go /START OMIT/,/END OMIT/
* switch (value)
.play -edit 05-control-structures/switchvalue.go /START OMIT/,/END OMIT/
* switch (conditions)
.play -edit 05-control-structures/switchcondition.go /START OMIT/,/END OMIT/
* Questions?
* Exercises
Exercise 1
- Write fizzbuzz for the numbers 1-100
- If the number is a multiple of 3, write fizz
- If the number is a multiple of 5, write buzz
- If the number is a multiple of 3 and 5, write fizzbuzz
- Otherwise print the number