{
  "format": "rpai-station-workflow",
  "version": 1,
  "name": "Conditions and loops",
  "variables": [],
  "activities": [
    {
      "id": "academy-001",
      "type": "comment",
      "name": "About this workflow",
      "properties": {
        "text": "Station Academy, Level 3. A loop with a counter, an If inside it and a Break. Touches no other app."
      }
    },
    {
      "id": "academy-002",
      "type": "set_variable",
      "name": "Start counting at zero",
      "properties": {
        "variableName": "n",
        "valueType": "static",
        "value": "0"
      }
    },
    {
      "id": "academy-011",
      "type": "loop",
      "name": "Repeat ten times",
      "properties": {
        "loopType": "count",
        "count": "10"
      },
      "children": [
        {
          "id": "academy-003",
          "type": "math_operation",
          "name": "Next number",
          "properties": {
            "operation": "add",
            "operand1": "n",
            "operand2": "1",
            "saveToVariable": "n"
          }
        },
        {
          "id": "academy-004",
          "type": "math_operation",
          "name": "Remainder after dividing by 2",
          "properties": {
            "operation": "modulo",
            "operand1": "n",
            "operand2": "2",
            "saveToVariable": "rest"
          }
        },
        {
          "id": "academy-007",
          "type": "if",
          "name": "Is it even?",
          "properties": {
            "variable": "rest",
            "operator": "equals",
            "value": "0"
          },
          "thenBranch": [
            {
              "id": "academy-005",
              "type": "log",
              "name": "Even",
              "properties": {
                "message": "{{n}} is even",
                "level": "info"
              }
            }
          ],
          "elseBranch": [
            {
              "id": "academy-006",
              "type": "log",
              "name": "Odd",
              "properties": {
                "message": "{{n}} is odd",
                "level": "info"
              }
            }
          ]
        },
        {
          "id": "academy-010",
          "type": "if",
          "name": "Stop at 7",
          "properties": {
            "variable": "n",
            "operator": "equals",
            "value": "7"
          },
          "thenBranch": [
            {
              "id": "academy-008",
              "type": "log",
              "name": "Leaving the loop",
              "properties": {
                "message": "Reached 7, stopping early.",
                "level": "info"
              }
            },
            {
              "id": "academy-009",
              "type": "break",
              "name": "Leave the loop",
              "properties": {}
            }
          ],
          "elseBranch": []
        }
      ]
    },
    {
      "id": "academy-012",
      "type": "set_variable",
      "name": "A short list",
      "properties": {
        "variableName": "fruits",
        "valueType": "static",
        "value": "apple,pear,plum"
      }
    },
    {
      "id": "academy-013",
      "type": "string_operation",
      "name": "Turn it into a list",
      "properties": {
        "operation": "split",
        "input": "{{fruits}}",
        "delimiter": ",",
        "saveToVariable": "fruitList"
      }
    },
    {
      "id": "academy-015",
      "type": "loop",
      "name": "For each fruit",
      "properties": {
        "loopType": "collection",
        "collection": "fruitList",
        "itemVariable": "fruit"
      },
      "children": [
        {
          "id": "academy-014",
          "type": "log",
          "name": "Fruit",
          "properties": {
            "message": "Fruit: {{fruit}}",
            "level": "info"
          }
        }
      ]
    },
    {
      "id": "academy-016",
      "type": "log",
      "name": "Done",
      "properties": {
        "message": "Finished at n = {{n}}",
        "level": "info"
      }
    }
  ]
}
