match as alternative to if and unless (#11407)
* match as alternative to if and unless * Update docs.md * Update docs.md * Update docs.mdpull/11426/head
							parent
							
								
									905c292a81
								
							
						
					
					
						commit
						f2f7abe2f4
					
				
							
								
								
									
										24
									
								
								doc/docs.md
								
								
								
								
							
							
						
						
									
										24
									
								
								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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue