Both `:when` and `:while` tests if an element should be used when building 
the resulting sequence. If the `:when` part evaluates to false (or nil) the 
element is skipped and the list comprehension continues with the next 
element in the source sequence. `:while` on the other hand ends the list 
comprehension when the test evaluates to false (or nil) and returns the 
sequence generated thus far.

Note the difference between

  (for [x [2 4 6 7 8] :when (even? x)] x) ; => (2 4 6 8)

and

  (for [x [2 4 6 7 8] :while (even? x)] x) ; => (2 4 6)

Hope that helps.

Jonas

On Tuesday, August 21, 2012 1:28:50 PM UTC+3, Nicolas Oury wrote:
>
> Dear all, 
>
> What is the meaning of :while in a for? 
> I understand :when, and also that :while jumps more element when the 
> condition is not met, 
> but where does it jump to exactly? 
>
> Best regards, 
>
> Nicolas. 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to