For the complete documentation index, see llms.txt. This page is also available as Markdown.

条件判断

与许多编程语言一样,Soulver 支持条件判断(有时称为“if 语句”)。

在 Soulver 中,条件判断在一行内表达:

earnings = $45k                                 | $45,000.00

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

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

以下示例只有英文写法;Soulver 在任何语言下都能识别英文写法。

使用条件判断声明变量

income = $35k
expenses = $21.5k

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

以下示例只有英文写法;Soulver 在任何语言下都能识别英文写法。

在条件判断中使用“和”与“或”(and 与 or)

BMI = 24
体重过轻 = BMI < 18.5                | false
健康体重 = BMI >= 18.5 和 BMI < 25   | true
超重 = BMI >= 25 和 BMI < 30         | false
肥胖 = BMI >= 30                     | false

&& 和 || 也受支持

比较运算符和布尔值

Soulver 支持标准的 "C" 风格 比较运算符。

返回一个布尔值(true 或 false)。

名称
运算符

等于

==

不等于

!=

大于

>

小于

<

大于或等于

>=

小于或等于

<=

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

以下示例只有英文写法;Soulver 在任何语言下都能识别英文写法。

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

最后更新于