thp-lang.org/md/learn/flow-control/match.md

40 lines
431 B
Markdown
Raw Normal View History

2023-10-02 01:41:38 +00:00
# Match
## Syntax
Braces are **required**.
2023-10-02 01:41:38 +00:00
```thp
2024-02-20 10:17:21 +00:00
val user_id = POST::get("user_id")
2023-10-02 01:41:38 +00:00
match user_id
| Some(id) { print("user_id exists: {id}") }
2023-10-02 01:41:38 +00:00
| None { print("user_id doesn't exist") }
match user_id
| Some(id)
{
print("user_id exists: {id}")
}
| None
{
print("user_id doesn't exist")
}
match user_id
| Some(id) if id > 0
{
print("user_id exists: {id}")
}
| _
{
print("user_id has other values ")
}
```