Clojure 中的 If/do语句函数

首页 / Clojure入门教程 / Clojure 中的 If/do语句函数

Clojure中的" if-do" 表达式用于允许为" if"语句的每个分支执行多个表达式。

If/do Expression - 语法

if(condition) (
   statement #1
   statement #1.1
)

(
   statement #2
   statement #2.1
)

以下是"if condition" 语句的示例。

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

;; This program displays Hello Learnfk
(defn Example [] (
   if (= 2 2)
      (do(println "Both the values are equal")
         (println "true"))
      (do(println "Both the values are not equal")
         (println "false"))))
(Example)

在上面的示例中," if"条件用于判断2和2的值是否相等。

上面的代码产生以下输出。

Both the values are equal
true

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

微服务架构核心20讲 -〔杨波〕

Linux内核技术实战课 -〔邵亚方〕

Serverless进阶实战课 -〔静远〕

AI大模型之美 -〔徐文浩〕

零基础GPT应用入门课 -〔林健(键盘)〕

结构写作力 -〔李忠秋〕

超级访谈:对话道哥 -〔吴翰清(道哥)〕

程序员职业规划手册 -〔雪梅〕

云原生基础架构实战课 -〔潘野〕

好记忆不如烂笔头。留下您的足迹吧 :)