Clojure - 巢狀 If 語句



有時需要像其他程式語言一樣相互嵌入多個“if”語句。在 Clojure 中,這可以透過在計算多重表示式時使用邏輯“and”來實現。

語法

以下是此語句的一般形式。

if(and condition1 condition2) statement #1 statement #2

示例

以下是實現多重條件的示例。

(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example [] (
   if ( and (= 2 2) (= 3 3))
   (println "Values are equal")
   (println "Values are not equal")))
(Example)

輸出

以上程式碼生成以下輸出。

Values are equal
clojure_decision_making.htm
廣告
© . All rights reserved.