Two For loops cause "not all control paths return a value"
Ok i have a pretty simple code that counts X and Y up,
Pretty Straightforward i assumed. Count them up, give the X and Y cords out as a FVector for further usage. Done that hundreds of times back when i learned Java in school. However now i get the mentioned message that not all control paths return a value. But the point with "for" loops is, that i have just one way through, no breaks, no conditions. Just go from -2/-2 25 times up to +2/+2, return it as a Vector and done. So what seems to be the issue here?
Without seeing the entire function, can't tell you positively about the error code. But, the loop that you did show is a mistake. It is not doing what your description for it is. It will return the first value, no incrementing will happen.
It is legal to return directly from in a for loop, but it is not good practice. There are break and continue keywords for a reason. If you want to end a loop early, set your variable, then break. A goto is perfectly acceptable to break from inside a nested for loop, it is actually maybe the only reason it's still in the language. But, you aren't testing for a condition inside the loop, so it makes no sense why you are returning out of it prematurely.
A local variable should be set, or appended to in the loop, then outside the loop at the bottom of the function return the variable if it is one. If your appending to a referenced list you don't need to return anything.
answered Jul 19 '16 at 05:23 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here