What is the Doseq statement in Clojure?
Overview
A Doseq statement is a loop statement like the for-each loop statement in another programming language.
Loop
A loop constantly executes a code block until a condition is satisfied.
The Doseq statement
A Doseq statement iterates over a sequence of data.
Syntax
(doseq (sequence)
statement#1)
Figure
Example
(ns clojure.examples.hello(:gen-class));; This program displays Hello World(defn doseqq [](doseq [n [0 1 2 6 7 3 6]](println n)))(doseqq)
Explanation
-
Line 5: We create a function
doseqqto demonstrate theDoseqloop. -
Line 6: We declare
Doseqand pass the sequence of values we want it to loop through. -
Line 7: We print all the values of the
nsequence. -
Line 8: We call the
doseqqfunction we created.