I’m using a “For Each Loop With Break”, and after I use break, the index is not what I expect. When I call break, the increment is still performed afterwards. I’ve made a small example here – when the index reaches 2, break is called. After the loop is complete, I print the value of the index, and it’s 3.
It’s not a big deal to work around, but it does seem like a bug coming from a programming background, where the loop expression is not executed after break is called. I’m using Unreal 4.7.1.
it seems that the “print string” takes the next array index wether it exists or not.
Try this: Put the print string into the loop after the branch>true. It should print a 2.
AND try this to be sure how the loop works after completed: Create an array with just 3 entries, so the index can just have a maximal of 2. And use your blueprint. Would be interesting, if it will crash or give out a 3 again
If it gives you a 3 again, try to get the size of the array. Would also be interesting, if the output of 3 increase the array
Everthing just thoughts how i would approach to this issue.
Thanks for the response! I ended up crafting my own foreach macro to solve the problem. It’s easy to work around, but mostly I wasn’t sure if this was intended to work this way. If you take a semi-equivalent c++ loop
int i;
for(i=0; i<6; ++i)
{
if(i == 2)
break;
}
std::cout << "i = " << i;
This will print 2. Mostly my post is that the functionality is different from what a programmer would expect. I created a version of the macro which works as expected: