目录

Dotimes 声明

'dotimes'语句用于执行语句'x'次。

语法 (Syntax)

以下是doseq语句的一般语法。

(dotimes (variable value)
   statement)

其中value必须是一个数字,表示循环需要迭代的次数。

以下是此循环的图解表示。

Dotimes声明

例子 (Example)

以下是'doseq'语句的示例。

(ns clojure.examples.hello
   (:gen-class))
;; This program displays Hello World
(defn Example []
   (dotimes [n 5]
   (println n)))
(Example)

在上面的例子中,如果执行println语句,我们使用dotimes语句重复该数字。 并且对于每次迭代,它还将变量n的值递增。

输出 (Output)

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

0
1
2
3
4
↑回到顶部↑
WIKI教程 @2018