From 6aa214828bc7783ca135e51b1f1685bd4ba881dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ali=20Sinan=20K=C3=B6ksal?= <alisinan@gmail.com>
Date: Fri, 8 Jul 2011 23:06:53 +0000
Subject: [PATCH] when-otherwise example

---
 cp-demo/When.scala | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 cp-demo/When.scala

diff --git a/cp-demo/When.scala b/cp-demo/When.scala
new file mode 100644
index 000000000..def9e813a
--- /dev/null
+++ b/cp-demo/When.scala
@@ -0,0 +1,20 @@
+import cp.Definitions._
+import cp.Terms._
+
+object When {
+  def main(args: Array[String]): Unit = {
+    for (x <- ((x: Int) => x >= 0 && x < 4).lazyFindAll) {
+      when (x < 3) {
+        println("I'm assuming x is less than three")
+      }
+
+      println(when(x < 2) {
+        "furthermore, less than two"
+      } otherwise {
+        "ok, it is not less than two"
+      })
+
+      val anInt: Int = when (x < 1) { 42 } // will throw an exception if x cannot be less than 1
+    }
+  }
+}
-- 
GitLab