add case statement type narrowing
This commit is contained in:
parent
20964a6116
commit
ec568389b2
1 changed files with 15 additions and 0 deletions
|
|
@ -48,4 +48,19 @@ $ nimrod c -r ./case_stmts.nim
|
|||
C
|
||||
Consonant
|
||||
negative
|
||||
```
|
||||
|
||||
Another feature of sets is that when possible, the possible types are narrowed to a range so that the following code works without requiring an else statement.
|
||||
|
||||
``` nimrod
|
||||
let x = 2
|
||||
case (x and 3) + 7
|
||||
of 7: echo "A"
|
||||
of 8: echo "B"
|
||||
of 9: echo "C"
|
||||
of 10: echo "D"
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r ./case_stmts_1.nim
|
||||
C
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue