" dotimes" 语句用于执行语句" x"次。
(dotimes (variable value) statement)
其中value必须是一个数字,该数字指示循环需要迭代的次数。
链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-dotimes-statement.html
来源:LearnFk无涯教程网
(ns clojure.examples.hello (:gen-class)) ;; This program displays Hello Learnfk (defn Example [] (dotimes [n 5] (println n))) (Example)
在上面的示例中,如果执行println语句,则使用dotimes语句重复该数字。对于每次迭代,它还会使变量n的值递增。
上面的代码产生以下输出。
0 1 2 3 4
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)