From 89394d0fab076765b637b0fe643d8f8950639817 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 2 Feb 2025 20:13:05 +0000 Subject: Add int arithmetic example --- examples/39-struct-methods/src/HelloWorld.shed | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/39-struct-methods/src/HelloWorld.shed (limited to 'examples/39-struct-methods/src') diff --git a/examples/39-struct-methods/src/HelloWorld.shed b/examples/39-struct-methods/src/HelloWorld.shed new file mode 100644 index 00000000..cfba064d --- /dev/null +++ b/examples/39-struct-methods/src/HelloWorld.shed @@ -0,0 +1,17 @@ +pub fun main() ! Io -> Unit { + print!(Count(1).message()); + print!(Count(2).message()); + print!(Count(3).message()); +} + +struct Count(value: Int) { + fun message(this) -> String { + if (this.value == 1) { + "one\n" + } else if (this.value == 2) { + "two\n" + } else { + "many\n" + } + } +} -- cgit v1.2.3