'dotimes'語(yǔ)句用于執(zhí)行語(yǔ)句“x”次。
以下是dotimes語(yǔ)句的一般語(yǔ)法。
(dotimes (variable value) statement)其中值必須是指示循環(huán)需要被迭代的次數(shù)的數(shù)字。
以下是'doseq'語(yǔ)句的示例。
(ns clojure.examples.hello (:gen-class)) ;; This program displays Hello World (defn Example [] (dotimes [n 5] (println n))) (Example)
在上面的例子中,我們使用dotimes語(yǔ)句來(lái)重復(fù)執(zhí)行println語(yǔ)句的次數(shù)。 并且對(duì)于每次迭代它也增加變量n的值。
以上示例將輸出以下結(jié)果:
0 1 2 3 4
更多建議: