Skip to content

Commit

Permalink
doc: describe what enums are in docs.md (vlang#23750)
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman authored Feb 17, 2025
1 parent 66e1d14 commit e964187
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3466,11 +3466,14 @@ This is a special case of a [sum type](#sum-types) declaration.

### 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
enum Color as u8 {
red
green
blue
red // the default start value is 0
green // the value is automatically incremented to 1
blue // the final value is now 2
}
mut color := Color.red
Expand All @@ -3482,6 +3485,7 @@ match color {
.green { println('the color was green') }
.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 {`.
Expand Down

0 comments on commit e964187

Please sign in to comment.