Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement foreach loop in clojure?

Tags:

Implementing a for loop in clojure seems to be easy, but how can I implement a foreach statement that reads each element in the list(vector) and does something?

like this...

(foreach i list expression) 

Thanks in advance!

like image 1000
JayX Avatar asked Mar 12 '11 22:03

JayX


People also ask

What is the syntax of foreach loop?

Syntax. For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.

Can we use for loop inside foreach?

Loops can be used to iterate over collection objects in PHP. The for and foreach loop can be used to iterate over the elements.

Can we use for loop inside foreach loop in C#?

foreach loop in C# C# foreach loop is used to iterate through items in collections (Lists, Arrays etc.). When you have a list of items, instead of using a for loop and iterate over the list using its index, you can directly access each element in the list using a foreach loop.

Is each a loop statement?

In computer programming, foreach loop (or for each loop) is a control flow statement for traversing items in a collection. foreach is usually used in place of a standard for loop statement.


1 Answers

Just replace for with doseq and you're all set. Don't use map, which is just as lazy as for.

like image 97
amalloy Avatar answered Sep 21 '22 15:09

amalloy