For Loop node in Blueprints: repeat a block for a range of indexes
For Loop fires one execution pulse for each index between First Index and Last Index. From 0 to 4 it runs the Loop Body five times, with Index showing the current number, and then the Completed pin fires once at the end. It runs the whole loop from a single pulse.
From the course
Taken from the hands-on project of the course; the lessons show every step on video.
What are the pins of the For Loop?
- An execution input and two data inputs, First Index and Last Index.
- Loop Body, the output that runs for each repetition, and Completed, which fires when the loop finishes.
- Index, a data output with the current index of the loop.
How do I test it?
- Connect the For Loop after Enable Input, which comes from Event Begin Play, and a Print String on Loop Body.
- Leave First Index at 0 and set Last Index to 4: five repetitions, for indexes 0, 1, 2, 3 and 4.
- Append the Index to the string with space loop in the other field: it prints 0 loop, 1 loop, 2 loop, 3 loop, 4 loop.
What does Completed do?
It fires only on the last iteration of the loop. Connect a Print String with END to it and the text prints once, after the fifth loop.
How is it different from Do N?
Do N needs a pulse each time to run again, while For Loop runs the loop body the number of times you define, whether the pulse is sent once or several times.
Free PDFs that go with this page
One-page guides made from the lessons, sent by e-mail.
- Flow control nodes — Branch, Switch, loops and gates on one page: what each node does and which pins to know.
- Blueprint Cheat Sheet — A free one-page PDF for Unreal Engine 4/5, made from the lessons of the course. Keep it next to your editor while you learn.
- Free PDFs
Frequently asked questions
How many times does a For Loop from 0 to 4 run?
Five times: for indexes 0, 1, 2, 3 and 4.
What is the Completed pin?
An output that fires after the last iteration.
Does a For Loop have to start at 0?
No, but 0 is the standard starting index; you can start at another number.