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

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

技术教程推荐

AI技术内参 -〔洪亮劼〕

持续交付36讲 -〔王潇俊〕

从0开发一款iOS App -〔朱德权〕

浏览器工作原理与实践 -〔李兵〕

说透敏捷 -〔宋宁〕

爆款文案修炼手册 -〔乐剑峰〕

eBPF核心技术与实战 -〔倪朋飞〕

徐昊 · AI 时代的软件工程 -〔徐昊〕

工程师个人发展指南 -〔李云〕

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