Unreal Engine & Blueprints / Unreal Engine
For loops and For Each Loops Unreal Engine 4 Blueprints
Legacy TutorialWritten guide
This tutorial is part of the CGI Nerd archive. Some software features, interfaces, or workflows may have changed since it was recorded.

Playing loads YouTube content. YouTube processes data after activation.
Watch on YouTubeIf the player is blocked or unavailable, use Watch on YouTube.
Use Blueprint loops to repeat an action over an integer range or over the elements of an array. The lesson prints each iteration, formats its data into messages and uses Completed for a final action. It also demonstrates visible stalls when a large loop prints many messages.
The title identifies Unreal Engine 4; the exact minor version is unverified. The input setup is the historical Actor/Player 0 mouse-event approach shown in the source. The example’s “players near me” array contains manually entered names—it does not detect players or measure distance.
Trigger a For Loop and count its inclusive indices correctly
At 00:00, create an Actor Blueprint and place it in the level. At 01:00, set Auto Receive Input to Player 0 and connect Left Mouse Button Pressed to a For Loop.
The loop’s First Index and Last Index identify the integer range. Connect Loop Body to Print String to observe each iteration. At 02:02, the instructor sets the last index to 5 while starting at 0.
The narration initially says that 0 to 0 would execute zero times and briefly calls 0 through 5 five iterations. Those counts are incorrect for the demonstrated inclusive range. 0 through 5 is six iterations: 0, 1, 2, 3, 4 and 5. A 0-through-0 range has one iteration. The subsequent printed index sequence in the recording supports the six-value result.
At 03:01, connect the Index value to Print String through the integer conversion. This reveals what the loop is doing more clearly than six identical “Hello” messages. Epic’s ForLoop reference identifies Index as the current iteration value and separates Loop Body from Completed.
Keep large-loop tests separate from useful game behavior
At 04:01, the source increases the last index through 1,000, 10,000 and 100,000 while printing on each iteration. The larger tests visibly stutter or freeze movement briefly before execution continues.
These are workload demonstrations, not performance guarantees. The number of iterations and the work performed inside each iteration both matter; repeated on-screen printing is itself part of the measured burden. With a starting index of zero, the inclusive endpoint also means those ranges contain one more iteration than the endpoint value alone suggests.
Return to the small 0–5 range for the instructional graph. The lesson does not implement time-sliced work, asynchronous processing or a frame-budget system. Do not infer that a large ordinary loop spreads its work smoothly across gameplay frames merely because it eventually finishes.
Format the index and run a completion action once
At 06:03, insert Format Text and enter a message with a named placeholder in braces. The placeholder creates an input that can receive the loop Index. Connect the formatted result to Print String, with any required text-to-string conversion supplied by Blueprint.
The source uses a message like “I have looped {number} times.” When that placeholder receives Index, its first displayed number is zero. That is an index, not the number of iterations already completed. A message such as “Current index: {number}” describes the demonstrated data more precisely without changing the loop.
At 07:02, connect Completed to a separate Print String. That message runs after the range has finished, rather than once for every index. The two execution outputs serve different jobs even though both can reach the same kind of print node.
A useful inspection is to count six body messages and one completion message for the 0–5 range. The source performs this through play testing, not through a separate automated test.
Replace the index range with a string array
At 09:00, switch to For Each Loop. Its input is an array rather than a pair of integer bounds. Create an array variable for the example names and set its element type to String.
At 10:03, the variable initially retains a Boolean-oriented display after the type change. Recompiling/rebuilding updates the editable entries, after which the instructor enters four names. Connect a Get of that array to the loop’s Array input; an incomplete connection had previously produced a compile error.
At 11:01, connect Loop Body to Print String and use Array Element as the message value. Each iteration supplies one name. The loop visits the array contents; no spatial query populates or filters those entries in this lesson.
Inspect the array’s type and entries before changing the loop if the output is unexpected. A correctly wired For Each Loop cannot turn manually entered strings into actual Actor references.
Distinguish an element’s value from its index
At 12:01, use Format Text to combine Array Element with a sentence. At 13:01, add Array Index to show the element’s position as well. For four names, the indices are 0–3.
Array Element is the value at that position; Array Index is its numbered location. Use the value when a message should identify the player name, and the index when the position itself is useful. Adding or removing an entry changes how many body executions occur.
At 14:02, connect Completed to a final message. The source says there are no more players near the viewer, but the graph has only finished iterating the supplied list. A more precise interpretation is “Finished reading the array,” not a new proximity result.
The completed exercise demonstrates two iteration shapes and their data outputs. Its limits are equally useful: range endpoints must be counted correctly, loop-body workload affects responsiveness, and a descriptive variable name does not implement the behavior it describes.