aboutsummaryrefslogtreecommitdiff
path: root/examples/12-while
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-02-02 20:13:05 +0000
committerMichael Williamson <mike@zwobble.org>2025-02-02 20:13:20 +0000
commit89394d0fab076765b637b0fe643d8f8950639817 (patch)
tree6852b4f81fd7f7812bb208df52b4e0cc8b1bcbdf /examples/12-while
parent67f010c93b11744b1f2f1c9403fd1e8d2b888acb (diff)
Add int arithmetic example
Diffstat (limited to 'examples/12-while')
-rw-r--r--examples/12-while/shed-examples.json59
-rw-r--r--examples/12-while/shed.json58
-rw-r--r--examples/12-while/src/Counting.shed18
3 files changed, 35 insertions, 0 deletions
diff --git a/examples/12-while/shed-examples.json5 b/examples/12-while/shed-examples.json5
new file mode 100644
index 00000000..3ca518d7
--- /dev/null
+++ b/examples/12-while/shed-examples.json5
@@ -0,0 +1,9 @@
+{
+ examples: [
+ {
+ project: ".",
+ bin: "counting",
+ expectedOutput: "one\ntwo\nmany",
+ },
+ ],
+}
diff --git a/examples/12-while/shed.json5 b/examples/12-while/shed.json5
new file mode 100644
index 00000000..68d4287c
--- /dev/null
+++ b/examples/12-while/shed.json5
@@ -0,0 +1,8 @@
+{
+ bins: [
+ {
+ name: "counting",
+ mainNamespace: "Counting",
+ },
+ ],
+}
diff --git a/examples/12-while/src/Counting.shed b/examples/12-while/src/Counting.shed
new file mode 100644
index 00000000..aa95f536
--- /dev/null
+++ b/examples/12-while/src/Counting.shed
@@ -0,0 +1,18 @@
+fun message(count: Int) -> String {
+ if (count == 1) {
+ "one\n"
+ } else if (count == 2) {
+ "two\n"
+ } else {
+ "many\n"
+ }
+}
+
+pub fun main() ! Io -> Unit {
+ var count = 1;
+
+ while (count != 4) {
+ print!(message(count));
+ assign count = count + 1;
+ }
+}