> For the complete documentation index, see [llms.txt](https://docs.newbot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.newbot.io/conversescript-syntax/loop.md).

# Loop

### while

The writing of a loop is as follows:

```typescript
@Event('start')
start() {
    nb = 0
    while (nb < 10) {
        > Total : { nb }
        > Give me a number
        Prompt()
        nb += :text
    }
    > Total : { nb }
    > Finish !
}
```

The scenario will be as follows:

* \[**Chatbot**] Total: 0
* \[**Chatbot**] Give me a number
* \[**User**] 3
* \[**Chatbot**] Total: 3
* \[**Chatbot**] Give me a number
* \[**User**] 4
* \[**Chatbot**] Total: 7
* \[**Chatbot**] Give me a number
* \[**User**] 6
* \[**Chatbot**] Total: 13
* \[**Chatbot**] Finish!

### for ... of

The `for ... of` loop allows you to browse a table:

```typescript
@Event('start')
start() {
    names = ['sam', 'jim']
    for (name of names) {
        > { name }
    }
}
```

It also works with a string, a number, and an object:

```typescript
@Event('start')
start() {

    a = 2
    b = 'hey'
    c = { name: 'sam', age: 18 }

    /*
        Result : 0, 1, 2
    */
    for (nb of a) {
        > { nb }
    }

    /*
        Result : 'h', 'e', 'y'
    */
    for (letter of b) {
        > { letter }
    }

    /*
        Result : 'sam', 18
    */
    for (data of c) {
        > { data }
    }
}
```
