> For the complete documentation index, see [llms.txt](https://documentation.soulver.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.soulver.app/zh/yu-fa-can-kao/general/conditionals-and-comparisons.md).

# 条件判断

在 Soulver 中，条件判断在一行内表达：

```
earnings = $45k                                 | $45,000.00

if earnings > $30k then tax = 20% else tax = 5% | 20%

My tax paid: earnings × tax                     | $9,000.00
```

**使用条件判断声明变量**

```
income = $35k
expenses = $21.5k

profitable = true if income > expenses     | true
insolvent = false unless expenses > income | false
```

**在条件判断中使用“and”和“or”**

```
BMI = 24
Underweight = BMI < 18.5                  | false
Healthy Weight = BMI >= 18.5 and BMI < 25 | true
Overweight = BMI >= 25 and BMI < 30       | false
Obese = BMI >= 30                         | false
```

{% hint style="info" %}
&& 和 || 也受支持
{% endhint %}

#### 比较运算符和布尔值

Soulver 支持标准的 ["C" 风格](https://en.wikipedia.org/wiki/C_\(programming_language\)) 比较运算符。

返回一个布尔值（`true` 或 `false`）。

| 名称    | 运算符 |
| ----- | --- |
| 等于    | ==  |
| 不等于   | !=  |
| 大于    | >   |
| 小于    | <   |
| 大于或等于 | >=  |
| 小于或等于 | <=  |

您可以直接给变量赋值一个布尔值

```
cost = $500                                 
discount = true                        
if discount then cost = cost - 10%
cost | $450.00
```

您也可以在 if 语句外部使用比较运算符

```
20km == 20,000 m   | true
11:30 am < 9:30 am | false
```
