# Repeat loop - how to make it work

**URL:** <https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411>\
**Category:** Gatling (Open-Source)\
**Created:** [January 29, 2022, 8:16am UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411 "2022-01-29T08:16:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![khiemtang](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@khiemtang](https://community.gatling.io/u/khiemtang)\
**Post date:** [January 29, 2022, 8:16am UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/1 "2022-01-29T08:16:03Z")

</div>

I am trying to get the repeat API to work in my simulation but no matter what I do, I can’t get the HTTP delete call to happen.  
Inside that repeat loop, I evaluate the URL string, print that out to the console then make the HTTP call.  
Any idea on how to get this code to work?

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/409535ce63e6540197ee8024ec8a96b296e770ef.png)

What I see printed on the console

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/3f3e6bef25614220912ce46485b541d5411ab19a.png)

Thanks,  
Khiem

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [January 29, 2022, 8:35am UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/2 "2022-01-29T08:35:47Z")

</div>

Please read [https://gatling.io/docs/gatling/reference/current/core/concepts/#immutability](https://gatling.io/docs/gatling/reference/current/core/concepts/#immutability)

You have to use Gatling DSL components (eg Gatling’s foreach).

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/409535ce63e6540197ee8024ec8a96b296e770ef.png)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/3f3e6bef25614220912ce46485b541d5411ab19a.png)

---

<div class="post-metadata">

**Author:** ![khiemtang](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@khiemtang](https://community.gatling.io/u/khiemtang)\
**Post date:** [January 29, 2022, 3:24pm UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/3 "2022-01-29T15:24:02Z")

</div>

Thanks, Stephane for the prompt response. I don’t find a lot of information on the foreach loop but managed to change my loop and got “No attribute named ‘list’ is defined”. I may miss something very basic and make the wrong assumption. What is my issue now?

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/dcbfc344a0da8203c073a8ee44ae075aa9393cc3.png)

Thanks,  
\KT

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/409535ce63e6540197ee8024ec8a96b296e770ef.png)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/3f3e6bef25614220912ce46485b541d5411ab19a.png)

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [January 29, 2022, 3:28pm UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/4 "2022-01-29T15:28:42Z")

</div>

1. bad session API usage: [https://gatling.io/docs/gatling/reference/current/core/session/session\_api/#setting-attributes](https://gatling.io/docs/gatling/reference/current/core/session/session_api/#setting-attributes)
2. what’s this “foreach().run”??? It should be named “on”, not “run”, see [https://gatling.io/docs/gatling/reference/current/core/scenario/#foreach](https://gatling.io/docs/gatling/reference/current/core/scenario/#foreach)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/409535ce63e6540197ee8024ec8a96b296e770ef.png)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/3f3e6bef25614220912ce46485b541d5411ab19a.png)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/dcbfc344a0da8203c073a8ee44ae075aa9393cc3.png)

---

<div class="post-metadata">

**Author:** ![khiemtang](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@khiemtang](https://community.gatling.io/u/khiemtang)\
**Post date:** [January 29, 2022, 6:22pm UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/5 "2022-01-29T18:22:21Z")

</div>

Thanks. My latest code below still giving me “[ERROR] i.g.c.s.LoopBlock$ - Condition evaluation crashed with message ‘No attribute named ‘listoflists’ is defined’, exiting loop”. It seems that line 104 has no effect.

```auto
100: }).then (exec
101: { session ->
102: val subLists = session.getList<String>("personaIds").chunked(50)
103: println("subLists:${subLists}")
104: session.set("listoflists", subLists)
105: session
106: }.foreach("#{listoflists}", "list").on(
107: exec { session ->
108: println(session.getList<String>("list"))
109: http("Remove Realm Personas").delete("/v1/personas?ids=${session.getList<kotlin.String>("list")}")

```

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/409535ce63e6540197ee8024ec8a96b296e770ef.png)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/3f3e6bef25614220912ce46485b541d5411ab19a.png)

 ![image.png](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/dcbfc344a0da8203c073a8ee44ae075aa9393cc3.png)

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [January 29, 2022, 7:51pm UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/6 "2022-01-29T19:51:52Z")

</div>

Clearly, you didn’t properly read the documentation. There’s a big warning block exactly explaining your error.

---

<div class="post-metadata">

**Author:** ![khiemtang](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@khiemtang](https://community.gatling.io/u/khiemtang)\
**Post date:** [January 30, 2022, 8:42am UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/7 "2022-01-30T08:42:19Z")

</div>

Sorry for being ignorant and careless but I couldn’t find the warning that you referred to. Is it related to the use of $ and # to reference a session attribute?

I still don’t understand why “#{listoflists}” is not available to the foreach loop. I had “session.set(“listoflists”, subLists)” before the foreach loop.

---

<div class="post-metadata">

**Author:** ![khiemtang](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@khiemtang](https://community.gatling.io/u/khiemtang)\
**Post date:** [January 30, 2022, 9:07am UTC](https://community.gatling.io/t/repeat-loop-how-to-make-it-work/6411/8 "2022-01-30T09:07:14Z")

</div>

I think I got it now. Session is immutable.
