From f17058b98a2b94cea4ed8abc7587f3545ec2c84b Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 24 Feb 2025 01:12:26 +0100 Subject: [PATCH] Add some identifiers --- src/expressions/if-expr.md | 5 +++++ src/expressions/loop-expr.md | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/expressions/if-expr.md b/src/expressions/if-expr.md index bf210f087..e6fef1630 100644 --- a/src/expressions/if-expr.md +++ b/src/expressions/if-expr.md @@ -107,10 +107,14 @@ if let E::X(n) | E::Y(n) = v { r[expr.if.chains] ## Chains of conditions +r[expr.if.chains.intro] Multiple condition operands can be separated with `&&`. + +r[expr.if.chains.order] Similar to a `&&` [_LazyBooleanOperatorExpression_], each operand is evaluated from left-to-right until an operand evaluates as `false` or a `let` match fails, in which case the subsequent operands are not evaluated. +r[expr.if.chains.bindings] The bindings of each pattern are put into scope to be available for the next condition operand and the consequent block. The following is an example of chaining multiple expressions, mixing `let` bindings and boolean expressions, and with expressions able to reference pattern bindings from previous expressions: @@ -144,6 +148,7 @@ fn nested() { } ``` +r[expr.if.chains.or] If any condition operand is a `let` pattern, then none of the condition operands can be a `||` [lazy boolean operator expression][_LazyBooleanOperatorExpression_] due to ambiguity and precedence with the `let` scrutinee. If a `||` expression is needed, then parentheses can be used. For example: diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index 353c6cacb..cfcf44949 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -66,17 +66,26 @@ r[expr.loop.while] >       [_Expression_]_except struct expression_\ >    | `let` [_Pattern_] `=` [_Scrutinee_] +r[expr.loop.while.intro] A `while` loop expression allows repeating the evaluation of a block while a set of conditions remain true. + +r[expr.loop.while.syntax] The syntax of a `while` expression is a sequence of one or more condition operands separated by `&&`, followed by a [_BlockExpression_]. +r[expr.loop.while.condition] Condition operands must be either an [_Expression_] with a [boolean type] or a conditional `let` match. If all of the condition operands evaluate to `true` and all of the `let` patterns successfully match their [scrutinee]s, then the loop body block executes. + +r[expr.loop.while.repeat] After the loop body successfully executes, the condition operands are re-evaluated to determine if the body should be executed again. + +r[expr.loop.while.exit] If any condition operand evaluates to `false` or any `let` pattern does not match its scrutinee, the body is not executed and execution continues after the `while` expression. +r[expr.loop.while.eval] A `while` expression evaluates to `()`. An example: