From ec568389b2dea5e955660a063f7f9a81cf3f5b15 Mon Sep 17 00:00:00 2001 From: flaviut Date: Thu, 19 Jun 2014 21:54:53 -0400 Subject: [PATCH] add case statement type narrowing --- content/case.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/content/case.md b/content/case.md index 5c9aa99..db8638a 100644 --- a/content/case.md +++ b/content/case.md @@ -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 ``` \ No newline at end of file