aboutsummaryrefslogtreecommitdiff
path: root/examples/sum.lyn
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sum.lyn')
-rw-r--r--examples/sum.lyn18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/sum.lyn b/examples/sum.lyn
new file mode 100644
index 0000000..a4dcf61
--- /dev/null
+++ b/examples/sum.lyn
@@ -0,0 +1,18 @@
+syntax for {init cond post body} {
+ eval init
+ while (eval cond) {
+ eval body
+ eval post
+ }
+}
+
+def sum {n} {
+ require n int
+ let s 0
+ for {let i 0} {< i n} {set i (+ i 1)} {
+ set s (+ s i)
+ }
+ return s
+}
+
+println (sum 1000000)