# Can you make a nested if statement without code?

**URL:** <https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376>\
**Category:** General\
**Created:** [26 September 2020 13:57 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376 "2020-09-26T13:57:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mad\_dad](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@mad\_dad](https://discourse.nodered.org/u/mad_dad)\
**Post date:** [26 September 2020 13:57 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/1 "2020-09-26T13:57:31Z")

</div>

Is there a way to make a nested if statement using only by structuring nodes out on the GUI vs. writing js in a function node? How would you do it?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 September 2020 14:15 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/2 "2020-09-26T14:15:02Z")

</div>

Can you provide an example of what you want to do.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2020 14:23 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/3 "2020-09-26T14:23:42Z")

</div>

You could use swtich nodes nested, a simple example.

```auto
[{"id":"1838876b.1af279","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"c892bfe8.cfbf18","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tall","vt":"str"},{"t":"eq","v":"short","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":240,"wires":[["813627ca.52ac1"],["56abe8e3.56dfb8"]]},{"id":"1c9eb799.329c5","type":"function","z":"1838876b.1af279","name":"","func":"msg.options = msg.payload.split(\"\\n\");\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":680,"wires":[[]]},{"id":"6ae981ae.b315f8","type":"switch","z":"1838876b.1af279","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":200,"wires":[["4fa89b.6653ff64"],["c892bfe8.cfbf18"]]},{"id":"4fa89b.6653ff64","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"red","vt":"str"},{"t":"eq","v":"blue","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":160,"wires":[["97a48419.188d28"],["1d1af41a.f28c5c"]]},{"id":"97a48419.188d28","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":120,"wires":[]},{"id":"1d1af41a.f28c5c","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":180,"wires":[]},{"id":"813627ca.52ac1","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":220,"wires":[]},{"id":"56abe8e3.56dfb8","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":280,"wires":[]},{"id":"32fa4fef.12e18","type":"inject","z":"1838876b.1af279","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"tall","payload":"2","payloadType":"num","x":110,"y":180,"wires":[["6ae981ae.b315f8"]]},{"id":"54728e44.635f1","type":"comment","z":"1838876b.1af279","name":"","info":"1 tall or short -will not pass\n2 red or blue - will not pass","x":180,"y":100,"wires":[]}]

```

added a and / or example

```auto
[{"id":"1838876b.1af279","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"c892bfe8.cfbf18","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tall","vt":"str"},{"t":"eq","v":"short","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":240,"wires":[["813627ca.52ac1"],["813627ca.52ac1"]]},{"id":"1c9eb799.329c5","type":"function","z":"1838876b.1af279","name":"","func":"msg.options = msg.payload.split(\"\\n\");\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":680,"wires":[[]]},{"id":"6ae981ae.b315f8","type":"switch","z":"1838876b.1af279","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":200,"wires":[["4fa89b.6653ff64"],["c892bfe8.cfbf18"]]},{"id":"4fa89b.6653ff64","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"red","vt":"str"},{"t":"eq","v":"blue","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":160,"wires":[["813627ca.52ac1"],["813627ca.52ac1"]]},{"id":"813627ca.52ac1","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":220,"wires":[]},{"id":"32fa4fef.12e18","type":"inject","z":"1838876b.1af279","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"tall","payload":"2","payloadType":"num","x":110,"y":180,"wires":[["6ae981ae.b315f8","d6ccee4f.cf6d6"]]},{"id":"54728e44.635f1","type":"comment","z":"1838876b.1af279","name":"or","info":"","x":190,"y":140,"wires":[]},{"id":"d6ccee4f.cf6d6","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"red","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":200,"y":280,"wires":[["5d7b9b63.83c39c"]]},{"id":"5d7b9b63.83c39c","type":"switch","z":"1838876b.1af279","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":340,"y":280,"wires":[["813627ca.52ac1"]]},{"id":"2f24968c.1e36e2","type":"comment","z":"1838876b.1af279","name":"and","info":"","x":260,"y":340,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![mad\_dad](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@mad\_dad](https://discourse.nodered.org/u/mad_dad)\
**Post date:** [26 September 2020 14:41 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/4 "2020-09-26T14:41:38Z")

</div>

I have 2 switches inputting to an XOR node. When a button is pressed I want the state of that XOR to stop/allow the message from the button to proceed.

 ![Screen Shot 2020-09-26 at 7.40.57 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91d9a0112a6b0d3c6017188aa26971df57eae5f7.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 September 2020 15:42 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/5 "2020-09-26T15:42:52Z")

</div>

Not sure what that has to do with nested if. Feed the XOR into a node-red-simple-gate to block or allow the message from the button. Alternatively (possibly better) feed the output of the XOR back to the button, with a change node so as it enables or disables the button.

---

<div class="post-metadata">

**Author:** ![mad\_dad](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@mad\_dad](https://discourse.nodered.org/u/mad_dad)\
**Post date:** [26 September 2020 16:11 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/6 "2020-09-26T16:11:23Z")

</div>

Oh, maybe I'm wrong. I was looking at it like, IF the button is pressed, IF the XOR is true, etc. I will try the simple gate. Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 November 2020 16:11 UTC](https://discourse.nodered.org/t/can-you-make-a-nested-if-statement-without-code/33376/7 "2020-11-25T16:11:28Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
