Skip to content

Commit

Permalink
example of iota
Browse files Browse the repository at this point in the history
  • Loading branch information
codingsince1985 committed Feb 18, 2019
1 parent 86740f0 commit a82a7d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -123,6 +123,17 @@ var foo, bar int = 42, 1302 // declare and init multiple vars at once
var foo = 42 // type omitted, will be inferred
foo := 42 // shorthand, only in func bodies, omit var keyword, type is always implicit
const constant = "This is a constant"

// iota can be used for incrementing numbers, starting from 0
const (
_ = iota
a
b
c = 1 << iota
d
)
fmt.Println(a, b) // 1 2 (0 is skipped)
fmt.Println(c, d) // 8 16 (2^3, 2^4)
```

## Functions
Expand Down

0 comments on commit a82a7d8

Please sign in to comment.