-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_02_constants.slide
70 lines (43 loc) · 1.93 KB
/
01_02_constants.slide
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
# Constants
## constants
- cannot be changed
- created at compile time
- can only be numbers, characters (runes), strings or booleans
- can be initialized with a literal or a expression
- if expression is used to initialize, it must be constant expressions, evaluatable by the compiler
////////////////////////////////////////////////////////////////////////////////////
## declaring constants
**syntax:**
const constantName datatype = value
.play -numbers _concepts/01_introduction/02constants/1-different-type-declaration.go /START OMIT/,/END OMIT/
## declaring constants
**multiple constants in same line**
.play -numbers _concepts/01_introduction/02constants/2-multiple-consts1.go /START OMIT/,/END OMIT/
: Note: this way of coding doesn't work for constants of different data types
## declaring constants
**multiple constants in group**
.play -numbers _concepts/01_introduction/02constants/2-multiple-consts2.go /START OMIT/,/END OMIT/
////////////////////////////////////////////////////////////////////////////////////
## enum: enumeration
## enum
**non enum example**
.play -numbers _concepts/01_introduction/02constants/3-enum0.go /START OMIT/,/END OMIT/
## enum
**manual enumeration**
.play -numbers _concepts/01_introduction/02constants/3-enum1.go /START OMIT/,/END OMIT/
## enum
**iota enumerator**
- integer type
- starts at 0 by default
.play -numbers _concepts/01_introduction/02constants/3-enum2a.go /START OMIT/,/END OMIT/
## enum
**iota enumerator**\
to start at a different number
.play -numbers _concepts/01_introduction/02constants/3-enum3.go /START OMIT/,/END OMIT/
## enum
**iota enumerator**\
to skip a part of the sequence
.play -numbers _concepts/01_introduction/02constants/3-enum4.go /START OMIT/,/END OMIT/
////////////////////////////////////////////////////////////////////////////////////
## constants at package level
.play -numbers _concepts/01_introduction/02constants/4-package-level.go /START OMIT/,/END OMIT/