mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-04-07 12:00:59 +01:00
Update syntax-if-statements-initializers.md
This commit is contained in:
parent
614a6c26f2
commit
b4e09afb9e
1 changed files with 18 additions and 1 deletions
|
@ -52,7 +52,24 @@ end
|
|||
|
||||
# Design
|
||||
|
||||
If statements with initializers must match (following the Luau grammar) `'if' 'local' bindinglist ['=' explist] 'then'` and `'local' bindinglist ['=' explist] where exp 'then'` syntax. The variables declared by an initializer are only available to the if statement's blocks; any code after the if statement won't have the variables defined.
|
||||
If statements with initializers must match the below grammar. The variables declared by an initializer are only available to the if statement's blocks; any code after the if statement won't have the variables defined.
|
||||
|
||||
```diff
|
||||
stat = varlist '=' explist |
|
||||
...
|
||||
'repeat' block 'until' exp |
|
||||
- 'if' exp 'then' block {'elseif' exp 'then' block} ['else' block] 'end' |
|
||||
+ 'if' cond 'then' block {'elseif' cond 'then' block} ['else' block] 'end' |
|
||||
'for' binding '=' exp ',' exp [',' exp] 'do' block 'end' |
|
||||
...
|
||||
|
||||
- ifelseexp = 'if' exp 'then' exp {'elseif' exp 'then' exp} 'else' exp
|
||||
+ ifelseexp = 'if' cond 'then' exp {'elseif' cond 'then' exp} 'else' exp
|
||||
|
||||
+ cond = 'local' binding '=' exp ['where' exp] |
|
||||
+ 'local' bindinglist '=' explist 'where' exp |
|
||||
+ exp
|
||||
```
|
||||
|
||||
In the former case, the value of the first declared variable will be checked.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue