mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
doc: describe what enums are in docs.md (#23750)
This commit is contained in:
parent
66e1d14bb4
commit
e9641875c3
1 changed files with 7 additions and 3 deletions
10
doc/docs.md
10
doc/docs.md
|
@ -3466,11 +3466,14 @@ This is a special case of a [sum type](#sum-types) declaration.
|
||||||
|
|
||||||
### Enums
|
### Enums
|
||||||
|
|
||||||
|
An enum is a group of constant integer values, each having its own name,
|
||||||
|
whose values start at 0 and increase by 1 for each name listed.
|
||||||
|
For example:
|
||||||
```v
|
```v
|
||||||
enum Color as u8 {
|
enum Color as u8 {
|
||||||
red
|
red // the default start value is 0
|
||||||
green
|
green // the value is automatically incremented to 1
|
||||||
blue
|
blue // the final value is now 2
|
||||||
}
|
}
|
||||||
|
|
||||||
mut color := Color.red
|
mut color := Color.red
|
||||||
|
@ -3482,6 +3485,7 @@ match color {
|
||||||
.green { println('the color was green') }
|
.green { println('the color was green') }
|
||||||
.blue { println('the color was blue') }
|
.blue { println('the color was blue') }
|
||||||
}
|
}
|
||||||
|
println(int(color)) // prints 1
|
||||||
```
|
```
|
||||||
|
|
||||||
The enum type can be any integer type, but can be omitted, if it is `int`: `enum Color {`.
|
The enum type can be any integer type, but can be omitted, if it is `int`: `enum Color {`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue