AutomationFlowsGeneral › Iterative Fibonacci Sequence Generator

Iterative Fibonacci Sequence Generator

Original n8n title: Iterative Fibonacci Sequence

Iterative Fibonacci Sequence. Uses manualTrigger, noOp, stickyNote. Event-driven trigger; 10 nodes.

Event trigger★★★★☆ complexity10 nodes
General Trigger: Event Nodes: 10 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "Iterative Fibonacci Sequence",
  "nodes": [
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "6e831eab-e2f2-4718-85c7-38f521eb9bbf",
                    "leftValue": "={{ $json.n }}",
                    "rightValue": 0,
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "return"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.n }}",
                    "rightValue": "={{ $('Input').item.json.n }}",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "id": "3933db04-251f-4bed-9db2-cfe8124aaf14"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "0"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "bea42f68-bcc3-4f92-b428-6f067a8bf9b5",
                    "leftValue": "={{ $json.n }}",
                    "rightValue": "={{ $('Input').item.json.n - 1 }}",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "1"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "f676349a-ff8a-4b2e-9c76-489c776ff0c1",
                    "leftValue": "={{ $json.n }}",
                    "rightValue": "={{ $('Input').item.json.n - 2 }}",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "2"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "4055d3db-02e1-46cd-a3fa-1ffeed17e56b",
                    "leftValue": "={{ $json.n }}",
                    "rightValue": 0,
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "a + b"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        448,
        224
      ],
      "id": "2526c28c-1e71-45d9-b893-0222bfe5a819",
      "name": "Switch"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "18fc4932-89b8-459d-941b-6e72cf5f89fc",
              "name": "fib",
              "value": "[]",
              "type": "array"
            },
            {
              "id": "0d8ecdc9-cfe5-4626-ac38-ad970ba321a7",
              "name": "n",
              "value": 10,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        272
      ],
      "id": "1bc30ee2-b061-4f9d-b423-37c7cdc0088f",
      "name": "Input"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        272
      ],
      "id": "b652e793-90a9-47b7-bf29-dab5ca38353a",
      "name": "Start"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1568,
        528
      ],
      "id": "7123394d-e8b8-4889-bdb3-15e3b0426f0b",
      "name": "End of Loop"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4498ae83-5a5a-48af-be77-b090fe101811",
              "name": "fib",
              "value": "={{ $json.fib.append($json.fib[$json.fib.length - 2] + $json.fib[$json.fib.length - 1]) }}",
              "type": "array"
            },
            {
              "id": "4be35049-32e8-4abc-8615-cc9ab8b43989",
              "name": "n",
              "value": "={{ $json.n - 1 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        672,
        528
      ],
      "id": "99177a96-a169-4d25-bdea-63fd87b3d241",
      "name": "Add a + b"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        672,
        128
      ],
      "id": "8bf48931-3e9a-475a-bf8b-5bf4fccbff40",
      "name": "Return"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d6bfe408-241e-4b27-9bc4-147af6e986dc",
              "name": "fib",
              "value": "={{ $json.fib }}",
              "type": "array"
            },
            {
              "id": "8fa12dac-d420-4806-94dc-25cb8597a17e",
              "name": "n",
              "value": "={{ $json.n - 1 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1344,
        240
      ],
      "id": "f0af7f21-f939-45cf-962d-6fdedd36f9c4",
      "name": "Empty"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "400a187b-99fe-44f4-9d7a-21473161a797",
              "name": "fib",
              "value": "={{ $json.fib.append(0) }}",
              "type": "array"
            },
            {
              "id": "70a3ec7b-27ed-4a8b-8f26-5ec0801af3a8",
              "name": "n",
              "value": "={{ $json.n - 1 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1120,
        336
      ],
      "id": "7cbaaf0a-d195-4b6a-a636-498bbaee98a9",
      "name": "Add 0"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "400a187b-99fe-44f4-9d7a-21473161a797",
              "name": "fib",
              "value": "={{ $json.fib.append(1) }}",
              "type": "array"
            },
            {
              "id": "70a3ec7b-27ed-4a8b-8f26-5ec0801af3a8",
              "name": "n",
              "value": "={{ $json.n - 1 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        896,
        432
      ],
      "id": "aaba22cf-599c-47ed-98d1-1f014a348976",
      "name": "Add 1"
    },
    {
      "parameters": {
        "content": "## Iterative Fibonacci Sequence\n\n### Introduction\n\nThis template provides a fun, low-code solution for generating a Fibonacci sequence of any length. Instead of using a single code block, it demonstrates a practical application of core n8n nodes to solve a classic programming problem.\n\n### The Idea\n\nThe template uses an iterative approach. It starts with a defined sequence length (`n`) and builds the Fibonacci array step-by-step within a loop. The loop is cleverly constructed using a `Switch` node for routing logic and `Set` nodes to update the sequence and a counter.\n\n### Purpose\n\nThis template is perfect for n8n users who want to deepen their understanding of logic and control flow within the platform. It serves as an educational example of how to implement iterative algorithms without writing custom JavaScript code.\n\n### Instructions for Setup\n\n1. **Input Node:** The workflow begins with a `Set` node named \"Input.\" You can modify the value of the `n` field in this node to define the length of the Fibonacci sequence you wish to generate.\n2. **Execution:** Run the workflow. The `Switch` node will manage the loop, and the `Set` nodes will add the correct numbers to the `fib` array.\n3. **Result:** The final result is the complete Fibonacci sequence, which can be viewed in the output of the final node.\n\n\nFor a step-by-step breakdown of how this workflow was built, check out the [full blog post here](https://n8nplaybook.com/post/2025/09/n8n-iterative-fibonacci-sequence/).",
        "height": 720,
        "width": 688
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        -528
      ],
      "typeVersion": 1,
      "id": "a7be6911-6c31-41cf-8c32-e6328aaddecf",
      "name": "Sticky Note"
    }
  ],
  "connections": {
    "Input": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Return",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Empty",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add 0",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add 1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add a + b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "End of Loop": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add a + b": {
      "main": [
        [
          {
            "node": "End of Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Empty": {
      "main": [
        [
          {
            "node": "End of Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add 0": {
      "main": [
        [
          {
            "node": "End of Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add 1": {
      "main": [
        [
          {
            "node": "End of Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3fd18bae-996d-4f4b-88fc-638f2bbca3dd",
  "id": "qa54ca7JuoZAuQWE",
  "tags": []
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow generates an iterative Fibonacci sequence, starting from the initial values of 0 and 1, and computes subsequent numbers by repeatedly adding the last two terms, allowing you to explore mathematical patterns or build foundational data for algorithms without manual calculations. It's ideal for educators, developers, or analysts who need a simple, repeatable way to produce Fibonacci numbers up to a desired length, saving time on repetitive arithmetic. The key step involves a switch node that controls the loop, combined with set nodes to update and store the accumulating values like 'a + b', ensuring precise progression through the sequence.

Use this workflow when you require a basic, event-driven generation of Fibonacci numbers for testing recursive logic or educational demos, particularly in environments where quick iterations matter without external data sources. Avoid it for large-scale computations needing high performance, as the 10-node chain suits small sequences best; opt for optimised scripts instead. Common variations include adjusting the loop limit in the switch for longer sequences or integrating outputs with tools like Google Sheets for visualisation.

About this workflow

Iterative Fibonacci Sequence. Uses manualTrigger, noOp, stickyNote. Event-driven trigger; 10 nodes.

Source: https://github.com/vklepikovskiy/n8nplaybook-public/blob/main/workflows/fibonacci.json — original creator credit. Request a take-down →

More General workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

General

Product - Google Search Console API Examples. Uses httpRequest. Event-driven trigger; 36 nodes.

HTTP Request
General

Metavoir Creative Intake To Review Brief. Event-driven trigger; 21 nodes.

General

Retry on fail except for known error Template. Uses stopAndError, noOp, stickyNote, manualTrigger. Event-driven trigger; 19 nodes.

Stop And Error
General

Retry on fail except for known error Template. Uses stopAndError. Event-driven trigger; 19 nodes.

Stop And Error
General

02 - Flow Control Demo (IF & Switch). Event-driven trigger; 16 nodes.