Iterate through a list

Uses a combination of conditional jumps, variables, and the len() function to iterate through a list.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

YAML

- define:
    assign:
      - array: ["foo", "ba", "r"]
      - result: ""
      - i: 0
- check_condition:
    switch:
      - condition: ${len(array) > i}
        next: iterate
    next: exit_loop
- iterate:
    assign:
      - result: ${result + array[i]}
      - i: ${i+1}
    next: check_condition
- exit_loop:
    return:
        concat_result: ${result}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.