Loops: Repeat Until the Finish Line
In this lesson you'll learn to
- βUse for and loop/break to iterate collections and run countdowns.
Use for and loop/break to iterate collections and run countdowns.
π Reference & full walkthrough: Loops: Repeat Until the Finish Line
π§© Your capstone piece: 3-2-1 race countdown loop and per-racer iteration
The Magic Repeater: Loops in Verse
Do you ever wish you could tell a prop to dance, but you have to click the button every single time? That is boring! Programming has a superpower called loops. A loop lets you tell your island to repeat an action many times, all by itself.
In this tutorial, we will build a "Spinny Disco Ball." It will spin around and around without you touching anything. We will use a loop to keep the spinning going forever. It is like a record player that never stops. Let's make some magic!
What You'll Learn
- What a loop is and why it is useful.
- How to make a device spin using Verse code.
- How to keep an action happening over and over again.
How It Works
<!-- section-art:how-it-works -->

Looping Motion
Imagine you are clapping your hands. If you want to clap five times, you can clap once, then again, and again. That is a small loop. But what if you want to clap for an hour? You would get tired!
A loop is like a robot helper. You tell the robot, "Keep doing this task until I say stop." In Verse, we use a special word called loop. It means "keep going forever, unless I tell you to break." We also use Sleep() to pause between steps.
We will use a device called a Prop Mover. Think of it like a remote control for a toy car. We can tell it to move, rotate, or slide. We will put our loop inside a Function. A function is like a recipe. You write the steps once, and then you can use them whenever you want.
Here is the plan:
- We create a Prop Mover.
- We write a function that tells the mover to start its movement sequence.
- We use a loop to keep nudging it forward again and again.
- The island spins forever!
Let's Build It
<!-- section-art:let-s-build-it -->

The Infinite Spin
First, go to UEFN. Place a Prop Mover device on your island. Name it DiscoBall. Make sure it is attached to a sphere prop if you want it to look nice.
Now, open the Verse editor. We need to write code. Here is the complete script. Copy it and paste it into your new Verse file.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }
# This is our main game manager class.
# It must inherit from creative_device so UEFN can run it.
disco_ball_device := class(creative_device):
# This is our Prop Mover device.
# Drag your DiscoBall Prop Mover onto this slot in the editor.
@editable
Mover : prop_mover_device = prop_mover_device{}
# How many degrees to add on each loop tick.
# Increase this number to spin faster.
SpinStepDegrees : float = 5.0
# Current accumulated rotation in degrees around the Z-axis (Yaw).
var CurrentYaw : float = 0.0
# OnBegin runs automatically when the game starts.
# It is the entry point for our device.
OnBegin<override>()<suspends> : void =
RunSpinLoop()
# This function contains the infinite spin loop.
RunSpinLoop()<suspends> : void =
# 'loop' repeats the block inside forever.
# It is the correct Verse keyword for an infinite loop.
loop:
# Add a small step to our running yaw total.
set CurrentYaw = CurrentYaw + SpinStepDegrees
# Tell the Prop Mover to move to the next keyframe.
# Prop Mover plays its configured movement on demand.
# We call Begin() each tick to advance the animation.
# note: PropMoverDevice does not expose SetRotation directly;
# configure the mover's keyframes in the editor for rotation,
# then drive it with Begin() each iteration.
Mover.Begin()
# Sleep pauses the loop for 0.05 seconds.
# Without this the loop runs thousands of times per second
# and can freeze the game. 0.05 s gives roughly 20 ticks/second.
Sleep(0.05)```
### Walkthrough of the Code
Let's look at the important parts.
**`loop:`**
This is the heart of the loop. In Verse, `loop` is the real keyword that means "repeat the code inside forever." The computer runs every line inside, reaches the bottom, and then jumps straight back to the top. It never stops on its own!
**`Mover.Play()`**
This line tells the Prop Mover to run its movement sequence. You set up the rotation keyframes in the UEFN editor, and `Play()` kicks them off each tick. It is like pressing the play button on a remote control every 0.05 seconds.
**`Sleep(0.05)`**
This is very important. Without this, the loop would run so fast that your computer might crash! The `Sleep` function pauses the code for a short time. `0.05` means 0.05 seconds. This makes the spin look smooth and nice.
**`OnBegin<override>()<suspends> : void`**
This is the special function that UEFN calls the moment your game starts. The `<suspends>` tag tells Verse that this function is allowed to pause and wait β which is required any time you use `Sleep()` or other timing tools inside it.
## Try It Yourself
Great job! You have a spinning disco ball. Now, let's make it more fun.
**Challenge:** Make the disco ball change color as it spins!
**Hint:**
1. Look at the **Prop Mover** device settings in the editor. Can you change its color there?
2. In Verse, devices often have properties you can change. Try finding a way to change the `Material` or `Color` property of the mover inside the loop.
3. You might need to use a list of colors. A list is like a shopping list. You can pick one item, then the next, then the next.
Don't worry if it doesn't work the first time. That is how we learn! Ask a friend or check the documentation if you get stuck.
## Recap
* A **loop** lets code repeat actions many times.
* We used the `loop` keyword to make a loop that never stops.
* We used a **function** to keep our code tidy and easy to read.
* We used `Sleep()` to make the loop run at a good speed.
You just made a device move on its own! You are a real Verse programmer. Keep building and have fun!
## References
* https://dev.epicgames.com/documentation/fortnite/verse-standup-comedy-club-template-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/verse-standup-comedy-club-template-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/your-first-island-level-up-with-verse-in-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/how-discover-works-in-fortnite
* https://dev.epicgames.com/documentation/fortnite/verse-api/versedotorg/scenegraph/keyframedmovement/loop_keyframed_movement_playback_mode
Keep going β free
You've read the intro. The rest of this lesson is free for members. Sign in to continue and track your progress.
Sign in free to continue this lessonSources
/guides/verse-loops-to-repeat-actions-on-your-islandBiloxi Studios original lesson
Add this lesson to your free study plan.
π§ The Keeperβs log
Quest complete? Chart your next heading from the π» North Jungle expedition.
β΅ Take me there