Skip to content

Commit

Permalink
教程添加对短路的说明
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Jan 27, 2025
1 parent 273aac1 commit a3ab2f4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ case 4:
> 和 DExp 有类似作用, 不过它的优先级是溢出的, 在许多地方需要加上括号使用
>
> `!` 运算并不实际存在, 它使用德摩根变换来反转内部条件, 直到反转到简单条件后结束
>
> `&&``||` 运算是短路的, 即:
> - `a && b` 在 a 不成立时, 直接返回不成立, 并不会计算 b 是否也不成立
> - `a || b` 在 a 成立时, 直接返回成立, 并不会计算 b 是否也成立
> 合理使用这种短路特性可以带来许多便利

简单语句
Expand Down Expand Up @@ -650,6 +655,13 @@ i, x = 2, abs(a-b) + sqrt(a)*2;

同时也提供三元运算等, 详见 [op-expr](./op_expr.mdtlbl)

> [!NOTE]
> op-expr 提供的 `||``&&` 运算优先级和 CmpTree 类似, 但是并不具备短路特性,
> `a && b` a 为假 b 就不求值, `a || b` a 为真 b就不求值.
>
> op-expr 的 `||``&&` 是使用 `+``land` 实现的,
> 只是为了有方便的优先级进行逻辑运算

关于注释
===============================================================================
Expand Down

0 comments on commit a3ab2f4

Please sign in to comment.