diff --git a/doc/docs.md b/doc/docs.md index f4de4958dc..78c27b7e04 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1572,6 +1572,30 @@ s := match number { } ``` +A match statement can also to be used as an `if - else if - else` alternative: + +```v +match true { + 2 > 4 { println('if') } + 3 == 4 { println('else if') } + 2 == 2 { println('else if2') } + else { println('else') } +} +// 'else if2' should be printed +``` + +or as an `unless` alternative: [unless Ruby](https://www.tutorialspoint.com/ruby/ruby_if_else.htm) + +```v +match false { + 2 > 4 { println('if') } + 3 == 4 { println('else if') } + 2 == 2 { println('else if2') } + else { println('else') } +} +// 'if' should be printed +``` + A match expression returns the value of the final expression from the matching branch. ```v