Loops

Learn about loops provided in Gatling.

In the previous lesson, we learned about checks. In this lesson, we will learn about the different loops offered by Gatling.

Gatling provides all basic loops, such as repeat, foreach, during, asLongAs, doWhile, asLongAsDuring, doWhileDuring, and forever. Let’s discuss them.

repeat

Repeat the loop a specified number of times. counterName is optional.

When counterName is provided, it will be added to the session of the user from which its value can be accessed. This applies to all the loop constructs.

repeat(times, counterName) {
  chainOfActions
}

times will be looked up in the user session.

repeat("${times}", counterName) {
  chainOfActions
}

We can fetch the value of key from a user session or anything that evaluates to Int.

repeat(session => session("key").as[Int], counterName) {
  chainOfActions
}

Get hands-on with 1400+ tech skills courses.