# Improving multiple, nested if-then-else statements

**URL:** <https://discourse.nodered.org/t/improving-multiple-nested-if-then-else-statements/96864>\
**Category:** General\
**Created:** [3 May 2025 08:18 UTC](https://discourse.nodered.org/t/improving-multiple-nested-if-then-else-statements/96864 "2025-05-03T08:18:16Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [3 May 2025 15:31 UTC](https://discourse.nodered.org/t/improving-multiple-nested-if-then-else-statements/96864/11 "2025-05-03T15:31:15Z")

</div>

Oooohhh - Finite State Machine (FSM) - the love of my life.  
I think you might be right - the code lends itself to being coded as an FSM (either using pure JavaScript or the Node-RED FSM node).

> [@Finite State Machine (FSM) with delay](https://discourse.nodered.org/t/finite-state-machine-fsm-with-delay/88275):
>
> I was asked the other day about how to create a Finite State Machine (FSM) with different delays between various transitions. Here is a simple example, based on the UK traffic light sequence, that makes use of the msg.delay option in the Delay node. Here's a screenshot of the flow. [{"id":"be3ab1ef.3f0a68","type":"tab","label":"Traffic Lights with variable delay","disabled":false,"info":"","env":[]},{"id":"743e732.c12228c","type":"function","z":"be3ab1ef.3f0a68","name":"Decode…

---

_[View the full topic](https://discourse.nodered.org/t/improving-multiple-nested-if-then-else-statements/96864)._
