Skip to main content

Loops in Verse: A Beginner's Guide

If you're just getting started with Verse (the programming language behind Fortnite Creative and UEFN), loops are one of the first big hurdles you'll run into. The good news? Once you get the hang of the two main loop types, they'll click fast. Let's break it down like you've never written a line of code before.

What's a Loop, Anyway?

A loop is just a way of telling the computer "do this thing over and over" instead of writing the same line of code a hundred times. Verse gives you two main tools for this: loop and for. They sound similar, but they do very different jobs.

One thing that makes Verse a little unusual: loops aren't just "do this repeatedly and forget about it." They can actually hand back a result when they're done, almost like a function returning an answer. Keep that in mind — it'll make more sense once we get to comprehensions below.

The loop Keyword: Repeat Forever (Until You Say Stop)

Think of loop as a treadmill that never turns off on its own. Once you start it, it just keeps going, and going, and going — until you physically hit the stop button. In Verse, that "stop button" is the break keyword.

If you forget to include a break somewhere inside your loop, you've basically built an infinite loop, and that will freeze up your game. So break isn't optional decoration — it's essential.

Here's what it looks like:

var Counter : int = 0

loop:
    set Counter += 1
    if (Counter > 5):
        break # Exits the loop completely

Walking through this line by line: we start a counter at zero, and every time the loop runs, we add one to it. Once the counter climbs past 5, the if check triggers and break kicks us out of the loop entirely.

A couple of things to keep in mind with loop:

  • Indentation isn't just for looks. In Verse, the code inside your loop needs to be indented consistently, or the compiler won't know what's actually inside the loop and what isn't.
  • It's great for "keep this running" situations. In actual game design, you'll often see loop paired with a sleep() call inside an async context — think of things like a countdown timer or a wave of enemies that spawns every few seconds. The sleep gives the game a breather between each repeat, so it doesn't lock everything up while it waits.

The for Expression: Repeat a Known Number of Times

While loop is for "keep going until I say stop," for is for "do this a specific number of times" or "go through each item in this list one by one." It's the tool you reach for when you already know roughly how much work needs to happen.

1. Looping Through a Range of Numbers

A "range" in Verse is just a span of numbers, written with two dots (..) between the start and end. The loop hands you each number in that range, one at a time.

# This will execute 11 times (0 through 10)
for (X := 0..10):
    Print("Current index: {X}")

Notice it runs 11 times, not 10 — Verse ranges include both the starting number and the ending number.

2. Looping Through a List of Things

Say you've got a list of players in your game and you want to do something to each one — heal them, teleport them, whatever. You don't need to manually track "which player number am I on." Verse lets you just grab each item directly:

Players : []player = GetSpace().GetPlayers()

for (Player : Players):
    HealPlayer(Player)

This reads almost like plain English: "for each player in Players, heal that player."

3. Loops That Build Something New (Comprehensions)

Here's where Verse gets a little more interesting than your average loop. Because loops in Verse can produce a value, you can use a for loop to transform a whole list of data into a brand new list — all in one line.

# Evaluates every item, multiplies it, and stores the resulting array
MyNumbers : []int = array{1, 2, 3}
MultipliedNumbers := for (X : MyNumbers) { X * 2 } 
# MultipliedNumbers now equals array{2, 4, 6}

Instead of writing a loop that manually builds a new list step by step, you just describe what you want each item to become, and Verse hands you the finished array.

The Rules for Wants You to Follow

Verse is a bit strict about how you write for loops, mainly to keep things predictable and performance-friendly. Here's what to watch out for:

  • Don't reuse your loop variable's name inside the loop. Once you've named your iteration variable (like X or Player above), you can't rename or redefine it partway through that same loop.
  • No var in the setup. You can't declare a mutable variable (using var) as part of the loop's setup section. Verse wants that part to stay predictable.
  • Filters need to be able to fail. If you add a condition inside the parentheses of your for loop to filter results, that condition has to be something that's genuinely capable of failing — like checking whether an index exists in an array — not just a simple true/false check.

Quick Recap

  • Use loop when you want something to repeat indefinitely, and don't forget your break.
  • Use for when you're working through a range of numbers or a collection of items you already have.
  • Remember that for loops can double as a way to build new data, not just repeat actions.

Got a specific loop you're trying to build — a timer, a way to filter game data, or something that transforms an array? Let me know what you're working on and I can put together a code template tailored to it.

Popular posts from this blog

C++ vcpkg Manifest Mode + CMake

 If you've ever tried to install a C++ library and felt like you were assembling furniture without instructions, this article is for you. We're going to talk about vcpkg manifest mode and how it works with CMake , and I'm going to explain it like you're five years old (in a good way — no judgment here). First, Let's Talk About the Problem In most programming languages, adding a library is easy. Python has pip install requests . JavaScript has npm install express . You type one command, and boom, the library shows up in your project. C++ never really had that. For decades, if you wanted to use a library like fmt or nlohmann/json , you had to: Download the source code yourself Figure out how to compile it Tell your compiler where to find the headers Tell your linker where to find the compiled binaries Cry a little vcpkg is Microsoft's answer to this mess. It's a package manager for C++ — like pip or npm , but for C++ libraries. And manifest mode...

How to Set Up a Linux Web Server and Host an HTML Page Easily

Setting up a web server on Linux means spending a fair amount of time in the terminal — Linux leans heavily on the command line rather than clicking through menus, so you'll be typing out instructions more often than not.  If you're new to this, it can feel a little intimidating at first, but the good news is you don't need to become a Linux wizard overnight. A handful of core commands will get you surprisingly far. A few you'll lean on constantly: cd — move between directories ls — see what's in the current directory mkdir — create a new folder nano or vim — edit files right there in the terminal sudo — run something with administrator privileges Get comfortable with these and you'll be able to navigate around, tweak configuration files, and install software without much trouble. You don't need to memorize everything — you just need to be confident enough to follow along with clear instructions, which is exactly what this guide aims to give you....

How to Check if Someone is Connected to Your Machine in Linux

Picture this: you glance at your system monitor and notice your CPU is humming along even though you're not running anything demanding. Or maybe your internet feels sluggish for no obvious reason. A small, uneasy thought creeps in — is someone else on my machine right now? For Linux users, this isn't something you have to wonder about. Linux ships with a powerful set of built-in tools that let you see exactly who's connected, who's logged in, and what your network is doing at any given moment. You don't need to be a security expert to use them — you just need to know where to look. This guide walks you through the practical, no-nonsense steps to check for unauthorized connections on your Linux system, with real commands you can run right now. Why Monitoring Network Connections Matters Every device on a network — including your own Linux machine — communicates using an IP address. When another device or user connects to your system, that connection shows up as a trac...