# Difference between for and for\*

**URL:** <https://racket.discourse.group/t/difference-between-for-and-for/2343>\
**Category:** Questions & Answers\
**Created:** [September 27, 2023, 2:47pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343 "2023-09-27T14:47:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matteo-daddio](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/matteo-daddio/32/1245_2.png) [@matteo-daddio](https://racket.discourse.group/u/matteo-daddio)\
**Post date:** [September 27, 2023, 2:47pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/1 "2023-09-27T14:47:27Z")

</div>

Hello,  
I’m working with for expressions.  
In these examples in the racket guide sometimes it is used _for_ and sometimes _for_\*

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/9/9174e3700590ee8ce48c8aae3afe2e0c1730eabd.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/4/45da70681c8cf6992e7b00709ae760006f8c5c4a.png)

and I can’t understand why.

Matteo

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [September 27, 2023, 3:09pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/2 "2023-09-27T15:09:56Z")

</div>

You are reading the section "11.9 Breaking an Iteration", which is toward the end of the guide. Have you read earlier sections (particularly "11.2 for and for\*") to understand how `for` and `for*` are different?

---

<div class="post-metadata">

**Author:** ![matteo-daddio](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/matteo-daddio/32/1245_2.png) [@matteo-daddio](https://racket.discourse.group/u/matteo-daddio)\
**Post date:** [September 27, 2023, 3:20pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/3 "2023-09-27T15:20:57Z")

</div>

Hi,  
yes, I’ve read it, but I still can’t understand the examples I’ve reported.

Matteo

---

<div class="post-metadata">

**Author:** ![scolobb](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/scolobb/32/108_2.png) [@scolobb](https://racket.discourse.group/u/scolobb)\
**Post date:** [September 27, 2023, 3:33pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/4 "2023-09-27T15:33:36Z")

</div>

Hi @matteo-daddio ,

The title of your post evokes the difference between `for` and `for*`, while the examples you cite focus on breaking conditions, i.e. facilities to stop iteration early, once some conditions are satisfied.

Based on this observation, I suggest that you come back to [11&nbsp;Iterations and Comprehensions](https://docs.racket-lang.org/guide/for.html#%28part._for_and_for_%29) , which gives the following answer to the question in the title of your post:

> The [for\*](https://docs.racket-lang.org/reference/for.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for%2A%29%29) form, which has the same syntax as [for](https://docs.racket-lang.org/reference/for.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for%29%29), nests multiple sequences instead of running them in parallel:

In other words, when you have two variables in a `for` iteration, _both_ advance at each step. On the other hand, when you have two variables in a `for*` iteration, the second (innermost) variable traverses the whole of its sequence _for each_ value the first variable takes in its own sequence. The first two examples in Section 11.2 I point to above should be rather illustrative.

Once you are all set with the difference between `for` and `for*`, the examples you include in original post should click.

---

<div class="post-metadata">

**Author:** ![matteo-daddio](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/matteo-daddio/32/1245_2.png) [@matteo-daddio](https://racket.discourse.group/u/matteo-daddio)\
**Post date:** [September 27, 2023, 3:44pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/5 "2023-09-27T15:44:34Z")

</div>

Hello,  
the post title I’ve chosen is a bit misleading. I think I’ve understood clearly the difference between _for_ and _for_\* and I think there’s a bug in the racket guide.

If you look carefully the examples I posted I think you’ll notice that all the for expressions should be for\*.

Am I wrong?

Matteo

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [September 27, 2023, 4:26pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/6 "2023-09-27T16:26:53Z")

</div>

What you are confused about is the behavior of `#:when` and `#:unless` within `for`, but this is already explained in “11.2 for and for\*”.

> A boolean-expr with #:when can refer to any of the preceding iteration bindings. In a [for](https://docs.racket-lang.org/reference/for.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for%29%29) form, this scoping makes sense only if the test is nested in the iteration of the preceding bindings; thus, bindings separated by #:when are mutually nested, instead of in parallel, even with [for](https://docs.racket-lang.org/reference/for.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for%29%29).

In other words, when there’s a `#:when` or `#:unless`, `for` clauses across the boundary are no longer iterated in parallel, but they become nested similar to `for*`.

---

<div class="post-metadata">

**Author:** ![matteo-daddio](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/matteo-daddio/32/1245_2.png) [@matteo-daddio](https://racket.discourse.group/u/matteo-daddio)\
**Post date:** [September 27, 2023, 5:19pm UTC](https://racket.discourse.group/t/difference-between-for-and-for/2343/7 "2023-09-27T17:19:08Z")

</div>

Thank you very much. I missed that. Now it’s clear. Thanks for the reply.

Matteo
