Loop x times when IF is false

WooCommerce has an order.created webhook.

If the order is made inside WooCommerce Store. It’ll trigger.

Then After 2 Mins of Wait.

WooCommerce Node will get the Order Status.

And with the help of IF Node.

  • If the status is processing It’ll send to TRUE Branch.

  • If the status is pending it’ll send to FALSE Branch (loop).

Then Again wait for 2 mins then the same thing comes in a loop.

But the problem is: If I don’t have a 3 times loop or Loop Limit. It’ll become a non-ending loop.

How to solve this issue? or Any Ideas on this?

Workflow:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "event": "order.created"
      },
      "name": "WooCommerce Trigger",
      "type": "n8n-nodes-base.wooCommerceTrigger",
      "typeVersion": 1,
      "position": [
        660,
        590
      ],
      "webhookId": "a6781718-8f00-4c4c-abbb-42e5aa54f7f1",
      "credentials": {
        "wooCommerceApi": "Store WooCommerece"
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "processing",
              "value2": "processing"
            }
          ]
        }
      },
      "name": "Check Payment Status",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1170,
        320
      ]
    },
    {
      "parameters": {
        "functionCode": "const waitTimeSeconds = 120;\n\nreturn new Promise((resolve) => {\n  setTimeout(() => {\n    resolve(items);\n  }, waitTimeSeconds * 1000);\n});\n\n"
      },
      "name": "Wait 2 Mins",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        920,
        590
      ]
    },
    {
      "parameters": {
        "resource": "order",
        "operation": "get",
        "orderId": "ID Here"
      },
      "name": "WooCommerce Get Payment Status",
      "type": "n8n-nodes-base.wooCommerce",
      "typeVersion": 1,
      "position": [
        930,
        320
      ],
      "credentials": {
        "wooCommerceApi": "Store WooCommerece"
      }
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1370,
        300
      ]
    }
  ],
  "connections": {
    "WooCommerce Trigger": {
      "main": [
        [
          {
            "node": "Wait 2 Mins",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Payment Status": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 2 Mins",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 Mins": {
      "main": [
        [
          {
            "node": "WooCommerce Get Payment Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WooCommerce Get Payment Status": {
      "main": [
        [
          {
            "node": "Check Payment Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Edited the Question with better clarity. @jan @RicardoE105 @harshil1712

Hey @mcnaveen!

Here is an example workflow that might help

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "let count = $node[\"Set\"].json.count\ncount++\n$node[\"Set\"].json.count = count;\nconsole.log(count);\nreturn [{json:{count}}];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [],
          "number": [
            {
              "name": "count",
              "value": 1
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [],
          "number": [
            {
              "value1": "={{$node[\"Function\"].json[\"count\"]}}",
              "value2": 5
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        750,
        160
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}