Iterate through a list

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

Explore further

For detailed documentation that includes this code sample, see the following:

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.