Tsallaka zuwa abun ciki
Justice Tech School

Constants

const declares a value fixed at compile time. A const block groups several. iota creates counting values, which is how Go does enums.

Example
package main

import "fmt"

const Pi = 3.14159

const (
	A = 1
	B = 2
)

type Day int

const (
	Monday Day = iota
	Tuesday
	Wednesday
)

func main() {
	fmt.Println(Pi, A+B, Tuesday, Wednesday)
}

Result

3.14159 3 1 2

Exercise

Declare a constant.

 Max = 10

Quiz Test

What does iota do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.