2022-02-14 02:22:51 +00:00
|
|
|
---
|
|
|
|
title: let
|
|
|
|
layout: command
|
2022-03-04 12:10:09 +00:00
|
|
|
version: 0.59.1
|
2022-02-14 02:22:51 +00:00
|
|
|
---
|
|
|
|
|
2021-05-30 00:57:04 +00:00
|
|
|
Create a variable and give it a value.
|
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
## Signature
|
|
|
|
|
|
|
|
```> let (var_name) (initial_value)```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
- `var_name`: variable name
|
|
|
|
- `initial_value`: equals sign followed by value
|
2021-05-30 00:57:04 +00:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
Set a variable to a value
|
2021-05-30 00:57:04 +00:00
|
|
|
```shell
|
2022-02-14 02:22:51 +00:00
|
|
|
> let x = 10
|
|
|
|
```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
2022-02-14 02:22:51 +00:00
|
|
|
Set a variable to the result of an expression
|
2021-05-30 00:57:04 +00:00
|
|
|
```shell
|
2022-02-14 02:22:51 +00:00
|
|
|
> let x = 10 + 100
|
|
|
|
```
|
2021-05-30 00:57:04 +00:00
|
|
|
|
2022-02-20 01:13:33 +00:00
|
|
|
Set a variable based on the condition
|
|
|
|
```shell
|
2022-03-03 00:55:03 +00:00
|
|
|
> let x = if false { -1 } else { 1 }
|
2022-02-20 01:13:33 +00:00
|
|
|
```
|