Match
The match
statement
match
statementA match statement is a short-hand way for if - else
. If the input is matched the statement block of the first matching branch will be executed and its last expression will be returned. The else
branch will be executed when there is no other matching branch.
One can also initialize variables using match
to have different values according to a condition.
Examples:
Enums
One can also match on enum
values (variants) as branches by using the .variant_here
syntax:
Exercises
Write a V program that creates an array of all even numbers from 1 to 50.
Write a V program that, given an array of numbers, returns the maximum value.
Write a V program that determines whether color (enum) is red or blue
Last updated