Loop

while

The writing of a loop is as follows:

@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:

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

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

@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 }
    }
}

Last updated