diff --git a/doc/docs.md b/doc/docs.md index b58d30105a..6fc68a2b09 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -813,6 +813,24 @@ A match statement can also be used to branch on the variants of an `enum` by using the shorthand `.variant_here` syntax. An `else` branch is not allowed when all the branches are exhaustive. +```v +c := `v` +typ := match c { + `0`...`9` { 'digit' } + `A`...`Z` { 'uppercase' } + `a`...`z` { 'lowercase' } + else { 'other' } +} +println(typ) // 'lowercase' +``` + +You can also use ranges as `match` patterns. If the value falls within the range +of a branch, that branch will be executed. + +Note that the ranges use `...` (three dots) rather than `..` (two dots). This is +because the range is *inclusive* of the last element, rather than exclusive +(as `..` ranges are). Using `..` in a match branch will throw an error. + ### Defer A defer statement defers the execution of a block of statements until the surrounding function returns.