For Loop retrieves one list item lower on Exit flow when Break Loop unit is used.

Ex-Crow 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 1

So here's a simple operation. I want to find an item in a list and then do something with it on For Loop's exit flow. The problem is that if the Break Loop unit is used to achieve this, the exit flow receives one item lower than you'd expect. 

Like in this image - I break the loop on the "5. CORRECT" item but on exit flow it retrieves one item lower  - "6. WRONG".

I can, however, achieve the desired result by using the "Cache" unit. But as far as I know, this specific scenario is not documented anywhere and had to be discovered through trial and error. 

Another point of interest is how For Loops retrieved item index differs when the Cache unit is in the graph. Without the Cache unit, the index value is "5" which again is one item lower than requested, but with Cache unit in the graph the index value is "4" which is correct. 

Bolt Version:
Unity Version:
2019.2, 2019.3
Scripting Backend:
.NET Version (API Compatibility Level):
.NET 4.x

Hi TowerCrow,

Thanks for the report. I'll have to recreate and test the C# behaviour too. I wonder what happens if you try to access a for loop index outside the loop after breaking in C# (whether it incremented it or not). I would mimic the C# behaviour in Bolt.