How this for loop works in ue4? pre or post incrementation?
for(int32 i = 1; i <=10; ++i)
{
//some code
}
my code is correct?
How this for loop works in ue4? pre or post incrementation?
for(int32 i = 1; i <=10; ++i)
{
//some code
}
my code is correct?
Hey there @Alexa.Ki! The for loop post increments every time it loops through the body in blueprints, so this will index out
1 2 3 4 5 6 7 8 9 10
And then it will stop looping and output on the completed pin. Same with your C++ example.
Thank you sir for reply, and I think I am pre incrementing
++i // pre incrementing
i++ // post incrementing
I should use i++ // post incrementing
according to my Blueprint Code
?
The fun part is that they both actually have the same output!
The reason this doesn’t matter in a for loop is that the flow of control works roughly like this:
Unless I’m highly mistaken right now.
Just In normal C++ the things are more simple, this is why I GOT confused by BP for loop.
int i = 1;
int j = 1;
int k = i++; // post increment
int l = ++j; // pre increment
std::cout << k; // prints 1
std::cout << l; // prints 2
Post increment implies the value i
is incremented after it has been assigned to k
. However, pre increment implies the value j is incremented before it is assigned to l
.
absolutely right
you could just add a Print Text node to the blueprint, and wire the Index to it, so you can see what it does.
yes I did the same and found this is post incrementation i++