Question: When I need to generate a sequence which needs "two loops", is it better to do something like this:

```
(for [x (range 1 4)] (map #(* x %) (range 6 9)))

```

or something like this:

```
(for [x (range 1 4)] (for [y (range 6 9)] (* x y)))

```

Both give the same result:

```
((6 7 8) (12 14 16) (18 21 24))

```

Is one more idiomatic than the other and what are the differences between these two?

Also, is it possible to get the same result by nesting two *map*?

Answer: 
Either is fine, but the second version scales better to arbitrary nesting levels.

Nesting `map` calls works, too:

```
user=> (map (fn [x] (map (fn [y] (* x y)) (range 6 9))) (range 1 4))
((6 7 8) (12 14 16) (18 21 24))

```

You cannot nest the shortcut function syntax, though.

By the way, just in case you actually need more set-comprehension-like semantics, `for` also has nesting built-in. The result is somewhat different:

```
user=> (for [x (range 1 4), y (range 6 9)] (* x y))
(6 7 8 12 14 16 18 21 24)

```
Remember `for` in clojure isn't a 'loop', it's a list comprehension. I find it easier to think backwards from the required value, rather than forwards from how I iterate.

It seems you are trying to create a sequence of values where the value is 

`(map #(* x %) y)`

* `x` is `1 >= x > 4` => `(range 1 4)`
* `y`, is `(range 6 9)` => `(repeat (range 6 9))`

But since you want the comprehension to terminate, you need a tweak to `y` giving

* `y` -> `[(range 6 9)]`

finally as an idiomatic list comprehension (note this is very similar to your first example, so you were almost there)

```
(for [x (range 1 4) y [(range 6 9)]] (map #(* x %) y))
((6 7 8) (12 14 16) (18 21 24))

```