# How to break array-loop node

**URL:** <https://discourse.nodered.org/t/how-to-break-array-loop-node/33367>\
**Category:** General\
**Created:** [26 September 2020 06:42 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367 "2020-09-26T06:42:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [26 September 2020 06:42 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/1 "2020-09-26T06:42:01Z")

</div>

I use the [array-loop](https://flows.nodered.org/node/node-red-contrib-loop-processing#array-loop) node to browse the array,  
I tried setting the node to break the array midway but it didn't work.  
Please tell me!  
Thanks.

For example, output to value C will **break** the array and continue to process outside `array-loop`

 ![array-loop](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af3d0e75a2c9ea0ce6d8e7e3ffb03864752aecf5.png)

```auto
[{"id":"7ee1d170.04bfe","type":"array-loop","z":"46ed97cd.a2aa08","name":"array-loop","key":"al1a60a19a718526","keyType":"msg","reset":true,"resetValue":"value-empty","array":"array","arrayType":"msg","x":560,"y":1500,"wires":[["8303299.a0144d8"],["dded6341.04cab"]]},{"id":"5f6ec320.8f0f4c","type":"inject","z":"46ed97cd.a2aa08","name":"msg.payload = \"A, B, C, D, E\"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"A, B, C, D, E","payloadType":"str","x":340,"y":1440,"wires":[["e6011028.90ed2"]]},{"id":"ad54dd1a.0a6a9","type":"debug","z":"46ed97cd.a2aa08","name":"out-loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":1500,"wires":[]},{"id":"e6011028.90ed2","type":"change","z":"46ed97cd.a2aa08","name":"split msg.payload by \", \"","rules":[{"t":"set","p":"array","pt":"msg","to":"$split(msg.payload, ', ')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1500,"wires":[["7ee1d170.04bfe"]]},{"id":"1ec40aac.050005","type":"function","z":"46ed97cd.a2aa08","name":"return msg","func":"if (\"C\" === msg.payload) {\n //return '';\n //return false;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":1640,"wires":[["63580b37.d78394","7ee1d170.04bfe"]]},{"id":"63580b37.d78394","type":"debug","z":"46ed97cd.a2aa08","name":"in-loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":1640,"wires":[]},{"id":"dded6341.04cab","type":"delay","z":"46ed97cd.a2aa08","name":"","pauseType":"delay","timeout":"0.5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":470,"y":1640,"wires":[["1ec40aac.050005"]]},{"id":"8303299.a0144d8","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"End Loop!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":1500,"wires":[["ad54dd1a.0a6a9"]]}]

```

---

<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 07:57 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/2 "2020-09-26T07:57:18Z")

</div>

Can you explain what you are actually wanting to do with the loop, I suspect there may be better ways.

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [26 September 2020 08:12 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/3 "2020-09-26T08:12:13Z")

</div>

> [@minhhn0205](#):
>
> I tried setting the node to break the array midway but it didn't work.

According to the documentation of the node you should:

> When the flow exits the loop, the key variable can reset by setting to null, undefined or empty string.

So I guess you should send something like msg.payload = "" to stop the array-loop.

If not working, you can also raise an issue to that [node github repository](https://github.com/s1r-J/node-red-contrib-loop-processing) to capture the authors attention.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 September 2020 08:15 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/4 "2020-09-26T08:15:12Z")

</div>

Tbh, I'm not certain that loop node is required at all. Pretty sure a split node would do this job. But as Colin said, what is the OP really trying to achieve.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [26 September 2020 16:23 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/5 "2020-09-26T16:23:28Z")

</div>

Thank everyone for the support!

> [@Colin](#):
>
> Can you explain what you are actually wanting to do with the loop, I suspect there may be better ways.

> [@Steve-Mcl](#):
>
> Tbh, I'm not certain that loop node is required at all. Pretty sure a split node would do this job. But as Colin said, what is the OP really trying to achieve.

@Colin, @Steve-Mcl I would like to explain more clearly what I want to do as follows:

I have a CSV file named _Summary\_File\_111222333\_20200920.CSV_ (★), containing a list of files with information such as _filepath_, _size_, _number of lines_, ... of the file:

> #filepath,date,size,rows  
> C:\Temp\Test\P\_File\_111222333\_20200920.CSV,20200920,52,15  
> C:\Temp\Test\M\_File1.CSV,20200920,10,3  
> C:\Temp\Test\M\_File2.CSV,20200920,32,10  
> C:\Temp\Test\M\_File3.CSV,20200920,22,7

I would like to check the information of the file such as whether _it exists or not_, _the size is correct or not_, _the number of lines of the file is correct_. (※)  
Therefore, after reading the file (★), I created an array of 5 rows and put in the `array-loop` node to check the information (※).  
If the information is not correct, it will output the error and **break out of the loop** , then execute the next node, but I don't know how to break out of `array-loop` when there is an error checking the file information.

Since I'm new to node-red, if there is a better way of doing file information check as mentioned above, please tell me!  
Any hint will be great.  
Thanks in advance.

 ![array-loop-1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b59f5abdc0c417d314ffc265a2fc230807e2a05b.png)

```auto
[{"id":"46ed97cd.a2aa08","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"60bb126a.2d426c","type":"inject","z":"46ed97cd.a2aa08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":130,"y":140,"wires":[["aca44e.f3b90bb"]]},{"id":"aca44e.f3b90bb","type":"file in","z":"46ed97cd.a2aa08","name":"","filename":"/Temp/Test/Summary_File_111222333_20200920.CSV","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":420,"y":140,"wires":[["630281e3.5373"]]},{"id":"cfc6955f.d26048","type":"change","z":"46ed97cd.a2aa08","name":"change","rules":[{"t":"set","p":"array","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":240,"wires":[["fd2bd1cb.3939f"]]},{"id":"94a080b8.010bc","type":"split","z":"46ed97cd.a2aa08","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":810,"y":240,"wires":[["6f972bc.379c0d4"]]},{"id":"6f972bc.379c0d4","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim(payload)\t","tot":"jsonata"},{"t":"set","p":"cnt","pt":"flow","to":"0","tot":"num"},{"t":"set","p":"cnt","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"cntRowP","pt":"flow","to":"0","tot":"num"},{"t":"set","p":"cntRowP","pt":"msg","to":"0","tot":"num"},{"t":"delete","p":"filenameLen","pt":"msg"},{"t":"set","p":"isInt","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":240,"wires":[["1fb23f26.307a31"]]},{"id":"630281e3.5373","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"filenameLen","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":200,"wires":[["17089737.a5a959"]]},{"id":"d4ef3b2e.d14ed8","type":"debug","z":"46ed97cd.a2aa08","name":"ログ出力","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":160,"wires":[]},{"id":"17089737.a5a959","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"filenameLen","pt":"msg","to":"$replace(filenameLen,/^.*[\\\\\\/]/, '')","tot":"jsonata"},{"t":"set","p":"filenameLen","pt":"msg","to":"$split(filenameLen,'.')[0]","tot":"jsonata"},{"t":"set","p":"filenameLen","pt":"msg","to":"$split(filenameLen,'_')","tot":"jsonata"},{"t":"set","p":"filenameLen","pt":"msg","to":"filenameLen.length","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":200,"wires":[["78582378.07850c"]]},{"id":"78582378.07850c","type":"switch","z":"46ed97cd.a2aa08","name":"","property":"filenameLen","propertyType":"msg","rules":[{"t":"lt","v":"4","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":200,"wires":[["60e8cc20.0fb704"],["94a080b8.010bc"]]},{"id":"60e8cc20.0fb704","type":"change","z":"46ed97cd.a2aa08","name":"エラーメッセージ設定","rules":[{"t":"set","p":"payload","pt":"msg","to":"util.outputLog('fnameChk',msg.filename,'制御')","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":160,"wires":[["d4ef3b2e.d14ed8"]]},{"id":"fd2bd1cb.3939f","type":"array-loop","z":"46ed97cd.a2aa08","name":"array-loop","key":"al1a60a19a718526","keyType":"msg","reset":false,"resetValue":"value-null","array":"array","arrayType":"msg","x":1020,"y":340,"wires":[["715aeff4.6f63a"],["6a153751.7e94e8","d70f6625.d671e8"]]},{"id":"d558d691.61b258","type":"debug","z":"46ed97cd.a2aa08","name":"msg end loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1460,"y":340,"wires":[]},{"id":"8da12b4c.16cf08","type":"function","z":"46ed97cd.a2aa08","name":"Func (cnt == 0)","func":"var cnt = flow.get('cnt');\ncnt += 1;\nflow.set('cnt',cnt);\nmsg.cnt = cnt;\n//node.warn('Func (cnt == 0) ' + cnt);\nmsg.payload = 'Func (cnt == 0) ' + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1220,"y":480,"wires":[["4fc0282f.243328"]]},{"id":"4fc0282f.243328","type":"debug","z":"46ed97cd.a2aa08","name":"msg","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1450,"y":480,"wires":[]},{"id":"6a153751.7e94e8","type":"delay","z":"46ed97cd.a2aa08","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":700,"y":480,"wires":[["1a02a480.95513c"]]},{"id":"1a02a480.95513c","type":"switch","z":"46ed97cd.a2aa08","name":"","property":"cnt","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":850,"y":480,"wires":[["c5ef4166.9fcbe","3f30dc84.374e84"],["9718cbce.87a908"]]},{"id":"9718cbce.87a908","type":"function","z":"46ed97cd.a2aa08","name":"Func (cnt != 0)","func":"var cnt = flow.get('cnt');\ncnt += 1;\nflow.set('cnt',cnt);\nmsg.cnt = cnt;\n//node.warn('Func (cnt != 0) ' + cnt);\nmsg.payload = 'Func (cnt != 0) ' + msg.payload;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1020,"y":560,"wires":[["4fc0282f.243328","fd2bd1cb.3939f"]]},{"id":"1fb23f26.307a31","type":"join","z":"46ed97cd.a2aa08","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1110,"y":240,"wires":[["cfc6955f.d26048"]]},{"id":"715aeff4.6f63a","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"End array-loop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1250,"y":340,"wires":[["d558d691.61b258"]]},{"id":"4417923f.d6febc","type":"debug","z":"46ed97cd.a2aa08","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":900,"wires":[]},{"id":"503af433.cf634c","type":"debug","z":"46ed97cd.a2aa08","name":"ログ出力","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":940,"wires":[]},{"id":"cd522055.a9bd4","type":"change","z":"46ed97cd.a2aa08","name":"エラーメッセージ設定","rules":[{"t":"set","p":"payload","pt":"msg","to":"outputLog('formatChk',msg.filename,'制御')","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":940,"wires":[["503af433.cf634c"]]},{"id":"8ce8ae23.7380d","type":"change","z":"46ed97cd.a2aa08","name":"Regex（So nguyen khong am）","rules":[{"t":"set","p":"isInt","pt":"msg","to":"$match(msg.isInt,/^\\d+$/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":780,"wires":[["5e436a40.9545f4","20ab1e05.dadb62"]]},{"id":"5e436a40.9545f4","type":"function","z":"46ed97cd.a2aa08","name":"2 <= 非負の整数（So nguyen khong am）か確認","func":"/*\n// 整数ではない場合\nif ('undefined' != typeof msg.isInt &&\n 2 <= msg.isInt.match) {\n return [msg,null];\n}\nelse {\n return [null,msg];\n}\n*/\n\nnode.warn('msg.isInt: ' + msg.isInt);\n\nif ('undefined' != typeof msg.isInt &&\n 2 <= payload) {\n msg.infoChk = \"OK\";\n node.warn(\"OK\");\n}\nelse {\n msg.infoChk = \"NG\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":880,"wires":[["4fc0282f.243328","fd2bd1cb.3939f"]]},{"id":"20ab1e05.dadb62","type":"debug","z":"46ed97cd.a2aa08","name":"cccc","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":760,"wires":[]},{"id":"c5ef4166.9fcbe","type":"debug","z":"46ed97cd.a2aa08","name":"aaaa","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"isInt","targetType":"msg","statusVal":"","statusType":"auto","x":970,"y":440,"wires":[]},{"id":"3f30dc84.374e84","type":"change","z":"46ed97cd.a2aa08","name":"change","rules":[{"t":"set","p":"isInt","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":640,"wires":[["8ce8ae23.7380d","b2c28e0f.9bbea"]]},{"id":"b2c28e0f.9bbea","type":"debug","z":"46ed97cd.a2aa08","name":"bbbb","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"isInt","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":620,"wires":[]},{"id":"d70f6625.d671e8","type":"debug","z":"46ed97cd.a2aa08","name":"xxx","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1250,"y":400,"wires":[]},{"id":"7ee1d170.04bfe","type":"array-loop","z":"46ed97cd.a2aa08","name":"array-loop","key":"al1a60a19a718526","keyType":"msg","reset":true,"resetValue":"value-empty","array":"array","arrayType":"msg","x":560,"y":1500,"wires":[["8303299.a0144d8"],["dded6341.04cab"]]},{"id":"5f6ec320.8f0f4c","type":"inject","z":"46ed97cd.a2aa08","name":"msg.payload = \"A, B, C, D, E\"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"A, B, C, D, E","payloadType":"str","x":340,"y":1440,"wires":[["e6011028.90ed2"]]},{"id":"ad54dd1a.0a6a9","type":"debug","z":"46ed97cd.a2aa08","name":"out-loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":1500,"wires":[]},{"id":"e6011028.90ed2","type":"change","z":"46ed97cd.a2aa08","name":"split msg.payload by \", \"","rules":[{"t":"set","p":"array","pt":"msg","to":"$split(msg.payload, ', ')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1500,"wires":[["7ee1d170.04bfe"]]},{"id":"1ec40aac.050005","type":"function","z":"46ed97cd.a2aa08","name":"return msg","func":"if (\"C\" === msg.payload) {\n //return '';\n //return false;\n //msg.al1a60a19a718526 = '';\n //return msg;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":1640,"wires":[["63580b37.d78394","7ee1d170.04bfe"]]},{"id":"63580b37.d78394","type":"debug","z":"46ed97cd.a2aa08","name":"in-loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":1640,"wires":[]},{"id":"dded6341.04cab","type":"delay","z":"46ed97cd.a2aa08","name":"","pauseType":"delay","timeout":"0.5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":470,"y":1640,"wires":[["1ec40aac.050005"]]},{"id":"8303299.a0144d8","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"End Loop!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":1500,"wires":[["ad54dd1a.0a6a9"]]},{"id":"46ef2d5d.f0df94","type":"inject","z":"46ed97cd.a2aa08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":450,"y":1860,"wires":[["99429554.1aef48"]]},{"id":"99429554.1aef48","type":"file in","z":"46ed97cd.a2aa08","name":"","filename":"/Temp/Test/Summary_File_111222333_20200920.CSV","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":740,"y":1860,"wires":[["739a5725.75d548"]]},{"id":"78ac054e.8af95c","type":"change","z":"46ed97cd.a2aa08","name":"change","rules":[{"t":"set","p":"array","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":1920,"wires":[["dcdca1cf.b1c6a"]]},{"id":"739a5725.75d548","type":"split","z":"46ed97cd.a2aa08","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":610,"y":1920,"wires":[["9b014320.d3285"]]},{"id":"9b014320.d3285","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim(payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":1920,"wires":[["f548407d.4b13b"]]},{"id":"b22ea460.c4a578","type":"array-loop","z":"46ed97cd.a2aa08","name":"array-loop","key":"al1a60a19a718526","keyType":"msg","reset":false,"resetValue":"value-null","array":"array","arrayType":"msg","x":1400,"y":2380,"wires":[["8a9e37c4.216938"],["7bc980a.0caac8"]]},{"id":"afc3003d.eefce","type":"debug","z":"46ed97cd.a2aa08","name":"msg end loop","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1840,"y":2380,"wires":[]},{"id":"b5f4df50.7cf6c","type":"function","z":"46ed97cd.a2aa08","name":"Func (cnt == 0)","func":"var cnt = flow.get('cnt');\ncnt += 1;\nflow.set('cnt',cnt);\nmsg.cnt = cnt;\n//node.warn('Func (cnt == 0) ' + cnt);\nmsg.payload = 'Func (cnt == 0) ' + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1560,"y":2520,"wires":[["b6c2755a.348b88","b22ea460.c4a578"]]},{"id":"b6c2755a.348b88","type":"debug","z":"46ed97cd.a2aa08","name":"msg","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1830,"y":2520,"wires":[]},{"id":"7bc980a.0caac8","type":"delay","z":"46ed97cd.a2aa08","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1080,"y":2520,"wires":[["55e849c9.d80ff8"]]},{"id":"55e849c9.d80ff8","type":"switch","z":"46ed97cd.a2aa08","name":"","property":"cnt","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1230,"y":2520,"wires":[["b5f4df50.7cf6c"],["9e004199.0b728"]]},{"id":"9e004199.0b728","type":"function","z":"46ed97cd.a2aa08","name":"Func (cnt != 0)","func":"var cnt = flow.get('cnt');\ncnt += 1;\nflow.set('cnt',cnt);\nmsg.cnt = cnt;\n//node.warn('Func (cnt != 0) ' + cnt);\nmsg.payload = 'Func (cnt != 0) ' + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1400,"y":2600,"wires":[["b6c2755a.348b88","b22ea460.c4a578"]]},{"id":"f548407d.4b13b","type":"join","z":"46ed97cd.a2aa08","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":950,"y":1920,"wires":[["78ac054e.8af95c"]]},{"id":"8a9e37c4.216938","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"End array-loop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1630,"y":2380,"wires":[["afc3003d.eefce"]]},{"id":"dcdca1cf.b1c6a","type":"array-loop","z":"46ed97cd.a2aa08","name":"array-loop","key":"al1a60a19a718526","keyType":"msg","reset":true,"resetValue":"value-empty","array":"array","arrayType":"msg","x":660,"y":2020,"wires":[["f771cae4.ef1188"],["ef6bb44f.31a818"]]},{"id":"7100e1c.9778e2","type":"debug","z":"46ed97cd.a2aa08","name":"out-loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":2020,"wires":[]},{"id":"ba885ac2.cea988","type":"function","z":"46ed97cd.a2aa08","name":"return msg","func":"if (\"C\" === msg.payload) {\n //return '';\n //return false;\n //msg.al1a60a19a718526 = '';\n //return msg;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":2160,"wires":[["3f8a9304.e5a7dc","dcdca1cf.b1c6a"]]},{"id":"3f8a9304.e5a7dc","type":"debug","z":"46ed97cd.a2aa08","name":"in-loop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":2160,"wires":[]},{"id":"f771cae4.ef1188","type":"change","z":"46ed97cd.a2aa08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"End Loop!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":2020,"wires":[["7100e1c.9778e2"]]},{"id":"ef6bb44f.31a818","type":"delay","z":"46ed97cd.a2aa08","name":"","pauseType":"delay","timeout":"0.5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":2160,"wires":[["ba885ac2.cea988"]]}]

```

[http://www.mediafire.com/file/7r39q8v909pmfaz/Test.zip/file](http://www.mediafire.com/file/7r39q8v909pmfaz/Test.zip/file)

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [27 September 2020 06:53 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/6 "2020-09-27T06:53:07Z")

</div>

> [@janvda](#):
>
> If not working, you can also raise an issue to that [node github repository](https://github.com/s1r-J/node-red-contrib-loop-processing) to capture the authors attention.

@janvda I raised an issue on the repository.

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [27 September 2020 08:10 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/7 "2020-09-27T08:10:54Z")

</div>

> [@minhhn0205](#):
>
> If the information is not correct, it will output the error and **break out of the loop** , then execute the next node,

Using split node you can loop through all files in _Summary\_File\_111222333\_20200920.CSV_ (★).  
For each file you perform the validation logic and then you add a switch node that checks this validation outcome and if it is OK performs the file processing logic.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [27 September 2020 14:33 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/8 "2020-09-27T14:33:03Z")

</div>

> [@janvda](#):
>
> Using split node you can loop through all files in _Summary\_File\_111222333\_20200920.CSV_ (★).

@janvda Thank you for your support!  
I have a folder containing many Summary files:

>  C:/Temp/  
>    |-Summary\_File1\_111222333\_20200920.CSV   
>    |-Summary\_File2\_111222333\_20200920.CSV   
>    |-Summary\_File3\_111222333\_20200920.CSV

with each Summary file having the same content as I mentioned above

> #filepath,date,size,rows  
> C:\Temp\Test\P\_File\_111222333\_20200920.CSV,20200920,52,15  
> C:\Temp\Test\M\_File1.CSV,20200920,10,3  
> C:\Temp\Test\M\_File2.CSV,20200920,32,10  
> C:\Temp\Test\M\_File3.CSV,20200920,22,7

 ![split-node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66016fa0abc918c36dffbb301ffd0905ca1fcab9.png)

```auto
[{"id":"95d2229a.45324","type":"inject","z":"91bb1229.328ef","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"C:/Temp/","payloadType":"str","x":380,"y":2740,"wires":[["908f2fb0.45783"]]},{"id":"908f2fb0.45783","type":"fs-ops-dir","z":"91bb1229.328ef","name":"","path":"payload","pathType":"msg","filter":"*","filterType":"str","dir":"files","dirType":"msg","x":540,"y":2740,"wires":[["131a876e.291719"]]},{"id":"970b1c58.d219b","type":"split","z":"91bb1229.328ef","name":"split 1","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":890,"y":2740,"wires":[["6e108628.e71db8"]]},{"id":"42bd1890.074558","type":"debug","z":"91bb1229.328ef","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1650,"y":2800,"wires":[]},{"id":"131a876e.291719","type":"change","z":"91bb1229.328ef","name":"","rules":[{"t":"set","p":"path","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"files","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":2740,"wires":[["970b1c58.d219b"]]},{"id":"e10456d9.0e3ac8","type":"file in","z":"91bb1229.328ef","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":890,"y":2800,"wires":[["d2dc4213.4039a"]]},{"id":"6e108628.e71db8","type":"change","z":"91bb1229.328ef","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"msg.path & msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":2800,"wires":[["e10456d9.0e3ac8"]]},{"id":"3391ae2.1e3ec52","type":"comment","z":"91bb1229.328ef","name":"Summary_File1_111222333_20200920.CSV↓","info":"","x":770,"y":2620,"wires":[]},{"id":"d2dc4213.4039a","type":"split","z":"91bb1229.328ef","name":"split 2","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1090,"y":2800,"wires":[["42bd1890.074558"]]},{"id":"b4bf8192.06dbb","type":"comment","z":"91bb1229.328ef","name":"Summary_File2_111222333_20200920.CSV↓","info":"","x":770,"y":2660,"wires":[]},{"id":"49bb6060.67662","type":"comment","z":"91bb1229.328ef","name":"Summary_File3_111222333_20200920.CSV↓","info":"","x":770,"y":2700,"wires":[]},{"id":"9392c93.00ae238","type":"comment","z":"91bb1229.328ef","name":"↑#filepath,date,size,rows","info":"","x":1150,"y":2840,"wires":[]},{"id":"5b2c3843.1813f8","type":"comment","z":"91bb1229.328ef","name":"↑C:\\Temp\\Test\\P_File_111222333_20200920.CSV,20200920,52,15","info":"","x":1280,"y":2880,"wires":[]},{"id":"c305902.41c1a7","type":"comment","z":"91bb1229.328ef","name":"↑C:\\Temp\\Test\\M_File1.CSV,20200920,10,3","info":"","x":1210,"y":2920,"wires":[]},{"id":"a680a4fa.6e1b58","type":"comment","z":"91bb1229.328ef","name":"↑C:\\Temp\\Test\\M_File2.CSV,20200920,32,10","info":"","x":1210,"y":2960,"wires":[]},{"id":"75b729be.994b38","type":"comment","z":"91bb1229.328ef","name":"↑C:\\Temp\\Test\\M_File3.CSV,20200920,22,7","info":"","x":1210,"y":3000,"wires":[]}]

```

After `split 1` node will read file _Summary\_File1\_111222333\_20200920.CSV_ and for each line of file will make a check such as whether _P\_File.CSV_, _M\_File.CSV_ exists or not, the size is correct or not, the number of lines of the file is correct (※).

Suppose, when checking information for line _C:\Temp\Test\M\_File1.CSV,20200920,10,3_ for **error** ,  
I want to output error log and do not want to check the next lines of file _Summary\_ **File1** \_111222333\_20200920.CSV_,  
but continue to check file _Summary\_ **File2** \_111222333\_20200920.CSV_,  
what should I do to **break at the loop of** `split 2` node?

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [27 September 2020 16:20 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/9 "2020-09-27T16:20:18Z")

</div>

> [@minhhn0205](#):
>
> Suppose, when checking information for line _C:\Temp\Test\M\_File1.CSV,20200920,10,3_ for **error** ,  
> I want to output error log and do not want to check the next lines of file

Instead of using the 2nd split node you might consider using a switch node with as input the following payload structure

```auto
"payload ": {
    "lines ": <array holding all the lines of the current file>
    "currentLineIndex ": <index of the line in "lines" to process next>
    "errorEncountered": <boolean indicating if an error is encountered during processing of the lines >
}

```

The switch should check if "errorEncountered" = False and that you haven't yet processed the last line (using currentLineIndex and length of lines array).

Like in in the initial array-loop example. You need to feed the payload back into the switch node. When doing so you must assure that "currentLineIndex " and "errorEncountered" is properly updated.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [27 September 2020 17:24 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/10 "2020-09-27T17:24:00Z")

</div>

@janvda Thank you for your enthusiastic guidance!  
I will think and try it.  
If there is a sample or reference document about what you instructed me to refer to, that would be great.

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [27 September 2020 20:39 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/11 "2020-09-27T20:39:41Z")

</div>

> [@minhhn0205](#):
>
> If there is a sample

A sample flow showing how you can structure the flow.

```auto
[{"id":"9010cd1c.e0768","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"36f438a5.85ac38","type":"inject","z":"9010cd1c.e0768","name":"file list","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"file1\",\"file2\",\"file3\"]","payloadType":"json","x":180,"y":80,"wires":[["7ed8b480.ede58c"]]},{"id":"7ed8b480.ede58c","type":"split","z":"9010cd1c.e0768","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":360,"y":80,"wires":[["645869fb.275b28","bd9df085.7b5b"]]},{"id":"645869fb.275b28","type":"debug","z":"9010cd1c.e0768","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":80,"wires":[]},{"id":"bd9df085.7b5b","type":"change","z":"9010cd1c.e0768","name":"<retrieve file lines>","rules":[{"t":"set","p":"lines","pt":"msg","to":"[\"TestP_File0.CSV\",\"TestM_File1.CSV\",\"TestM_File2.CSV\",\"TestM_File3.CSV\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":180,"wires":[["dbe9da2f.dc8078","7640d045.bd47e"]]},{"id":"dbe9da2f.dc8078","type":"debug","z":"9010cd1c.e0768","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":180,"wires":[]},{"id":"7640d045.bd47e","type":"change","z":"9010cd1c.e0768","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"file\" : payload,\t \"lines\" : lines,\t \"currentLineIndex\" : 0\t}\t ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":260,"wires":[["1beee482.2aa09b"]]},{"id":"1beee482.2aa09b","type":"switch","z":"9010cd1c.e0768","name":"Not end of lines ?","property":"payload.currentLineIndex != $count(payload.lines)\t","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":260,"wires":[["2b431fad.e0153","de1b1feb.8b0df"]]},{"id":"2b431fad.e0153","type":"function","z":"9010cd1c.e0768","name":"<process line with currentLinesIndex>","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":320,"wires":[["72bc4220.7aab2c"]]},{"id":"de1b1feb.8b0df","type":"debug","z":"9010cd1c.e0768","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":260,"wires":[]},{"id":"c8dd22ea.91482","type":"change","z":"9010cd1c.e0768","name":"increment currentLineIndex","rules":[{"t":"set","p":"payload.currentLineIndex","pt":"msg","to":"payload.currentLineIndex+1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":460,"wires":[["1beee482.2aa09b"]]},{"id":"72bc4220.7aab2c","type":"switch","z":"9010cd1c.e0768","name":"error ?","property":"/* randomly generates error with 20% */\t$random() < 0.2","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":380,"wires":[["3adff04a.907cc"],["c8dd22ea.91482"]]},{"id":"3adff04a.907cc","type":"debug","z":"9010cd1c.e0768","name":"error happened","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.file","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":380,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a39481e09969deab4840dc96aa6eab78df7db59.png)

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [28 September 2020 05:08 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/12 "2020-09-28T05:08:26Z")

</div>

@janvda Thank you very much!  
I am trying to follow what you instructed...

---

<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:** [27 November 2020 05:08 UTC](https://discourse.nodered.org/t/how-to-break-array-loop-node/33367/13 "2020-11-27T05:08:43Z")

</div>

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