-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.go
64 lines (46 loc) · 1.16 KB
/
constants.go
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
package main
import (
"fmt"
//"math"
)
// example for iota
const (
a = iota
b = iota
c = iota
// same as
// a = iota
// b
// c
// the value of iota is scoped to this constant block so it resets if we declare a new block
)
const (
a2 = iota
b2
c2
)
func main() {
// Naming convention
// If you want to export the constant than make the first char to uppercase and use camelcase for naming'
// If you wont export the constant than begin with a lowercase character
// const MyConstant int = 1
// const myConstant int = 1
// typed constant
const myConst int = 1
fmt.Printf("%v, %T\n", myConst, myConst)
// Constants need to be initalized by compile time. That means we need to assign a value to every constant
// Doesnt work
// const a int
// Thah also doesnt work because the functions needs to execute
// const res float64 = math.Sin(1)
// iota Enumerated constants
// iota can be used for incrementing numbers, starting from 0
// the initial value of iota is an int
fmt.Printf("%v\n", a)
fmt.Printf("%v\n", b)
fmt.Printf("%v\n", c)
fmt.Printf("%v\n", a2)
fmt.Printf("%v\n", b2)
fmt.Printf("%v\n", c2)
fmt.Printf("%v\n", a == a2)
}