summaryrefslogtreecommitdiff
path: root/Switch
diff options
context:
space:
mode:
authorseh <henesy.dev@gmail.com>2019-03-03 22:43:25 -0600
committerseh <henesy.dev@gmail.com>2019-03-03 22:43:25 -0600
commit6a49bdd014794981f99ed32969b3dac2db78e981 (patch)
tree4e39b65321e36b6e0a9a97fade41649ee0c1727c /Switch
parent7635c9c15d25fce6b392f9899a68a36cdd7c06c4 (diff)
add explanation for switch
Diffstat (limited to 'Switch')
-rw-r--r--Switch/README.md17
1 files changed, 10 insertions, 7 deletions
diff --git a/Switch/README.md b/Switch/README.md
index 92be1f4..9bfe55f 100644
--- a/Switch/README.md
+++ b/Switch/README.md
@@ -2,31 +2,33 @@
Limbo does not have a verbatim `switch` statement. Rather, it has a statement named `case` which is analogous, but not identical to C's switch-case construct.
-Limbo case statements break by default and accept range matching operations involving the `or` and `to` keywords.
-
-Note: A break or continue followed by a label causes a break out of, or the next iteration of, the enclosing construct that is labeled with the same label.
-
## Source
### switch.b:16,31
+This segment exemplifies a few features of limbo's case statement. There is an iterative loop wrapped around a case statement which has a boolean `or`'d section and a default section, indicated by the wildcard `*` operator.
+
+Limbo case statements break by default and accept range matching operations involving the `or` and `to` keywords.
+A break or continue followed by a label causes a break out of, or the next iteration of, the enclosing construct that is labeled with the same label.
### switch.b:33,42
-
+This case statement demonstrates the use of the `to` range operator in a given section while providing a specific section to match the `C` character as well.
### switch.b:44,51
-
+Limbo is able to switch on string values, this can include a `nil` check, demonstrated by the `""` section. Note that there is no default section provided. The default section is not mandatory.
### switch.b:53,60
-
+This case verifies whether a value is `0` or `1` to determine if a value is binary.
### switch.b:62,69
+The valid types for case statements include: `int`, `string`, and `big`.
+Note that the `big` coercion statement is mandatory.
## Demo
@@ -44,3 +46,4 @@ Note: A break or continue followed by a label causes a break out of, or the next
## Exercises
- Try commenting out the `break` and/or `continue` keywords in the first switch, how does the behavior change?
+- Change the variable `c` to equal `'C'`, what's printed?