Skip to main content

Verse, control flow

If you're coming from C++, Blueprint, or Python, Verse is going to trip you up at first. Not because it's harder—because it thinks about control flow in a completely different way.

Most languages care about true and false. Verse cares about success and failure. That single shift changes how you write conditionals, loops, and even simple array lookups. Once it clicks, though, you'll find it's actually a cleaner way to handle the "what if this doesn't work" problem that every game script eventually runs into.

Let's break down how it actually works.

Conditionals Aren't Just Yes/No Anymore

Here's the first surprise: if in Verse isn't just a branch—it's an expression. That means it can hand you back a value, not just decide which path to run.

IsGameOver : logic = false

if (IsGameOver?):
    Print("Game Over!")
else:
    Print("Keep Playing!")

Notice that ? sitting after IsGameOver. You can't skip it. Verse won't just look at a logic variable and assume you want to test it—you have to explicitly ask it to succeed. Forget the ? and your code won't compile the way you expect.

Because if returns a value, you can skip the whole "declare a variable, then set it inside a branch" dance:

Score : int = 120
ScoreStatus := if (Score > 100) then "High Score" else "Low Score"

One line. No temp variable. No mutation. That's the kind of thing that feels awkward the first time you write it and then becomes your default habit within a week.

When You Need More Than Two Branches

Stacking if-else chains gets ugly fast, especially once you're past three or four options. That's where case comes in—it's Verse's answer to switch statements, and it reads a lot more naturally.

ItemCount : int = 3

case (ItemCount):
    1 => Print("You have one item.")
    2 => Print("You have two items.")
    3 => Print("You have three items!")
    _ => Print("You have a lot of items.")

That underscore at the bottom isn't decoration—it's your catch-all. Leave it out and you risk a case with no matching branch, which is exactly the kind of silent bug that eats an afternoon.

Loops: Two Tools, Two Very Different Jobs

Verse gives you loop and for, and they're not interchangeable. Picking the wrong one is a common rookie mistake.

loop — For When You Don't Know How Many Times

loop just keeps going. Forever. Unless you tell it to stop.

var Counter : int = 0

loop:
    set Counter += 1
    Print("Loop count: {Counter}")
    
    if (Counter >= 5):
        break

That break isn't optional here—it's load-bearing. Without it, this loop never ends. Use loop when the exit condition depends on something happening during execution, not something you can calculate up front.

for — For When You're Iterating Over Something

for is where Verse really shows off. It doesn't just walk through arrays and ranges—it filters as it goes, right inside the loop header.

for (Index := 1..5):
    Print("Current number: {Index}")

Straightforward enough. But here's the part that'll save you real time:

Numbers : []int = array{1, 2, 3, 4, 5, 6}

for (Num : Numbers, Num % 2 == 0):
    Print("Found an even number: {Num}")

That second clause—Num % 2 == 0—is a built-in filter. If it fails on a given item, Verse doesn't crash or throw an error. It just quietly skips to the next one. No continue keyword needed, no nested if inside your loop body cluttering things up.

The Real Heart of Verse: Failure Contexts

This is the part that actually separates Verse from everything else you've used, so it's worth slowing down for.

Some operations in Verse are labeled decides—meaning they're allowed to fail instead of crashing your program. Pulling an item from an array by index is a perfect example. What happens if the index is out of range? In most languages, that's a runtime error, maybe a crash, maybe an ugly exception you have to catch.

In Verse, it just... fails gracefully. But only if you've wrapped it in a failure context—somewhere the language knows how to handle a fail state, like an if condition or a for filter.

Inventory : []string = array{"Sword", "Shield", "Potion"}

if (Item := Inventory[3]):
    Print("Found item: {Item}")
else:
    Print("Index out of bounds! The operation safely failed instead of crashing.")

Index 3 doesn't exist in a three-item array (remember, indexing starts at 0). Instead of blowing up, that access simply fails, and control drops into the else block. No try-catch. No exception handling boilerplate. Just a clean, built-in escape hatch.

This is the mental shift you need to make: in Verse, failure isn't an error. It's a normal, expected outcome that you design around.

Putting It All Together

Here's a script that combines everything above—loop, filtered iteration, and safe fallible indexing—into one working example:

using { /Verse.org/Simulation }

RunControlFlowDemo() : void =
    Scores : []int = array{45, 110, 85, 150, 30}
    
    Print("--- Finding High Scores ---")
    for (Score : Scores, Score > 100):
        Print("Passed Milestone: {Score}")
        
    Print("--- Safe Array Processing ---")
    var Index : int = 0
    loop:
        if (CurrentScore := Scores[Index]):
            Print("Processing score at index {Index}: {CurrentScore}")
            set Index += 1
        else:
            Print("Reached the end of the array.")
            break

Look closely at that second block. The loop doesn't check Index < Scores.Length the way you might in another language. It just keeps trying to read the next index—and when that read fails (because you've walked off the end of the array), the else branch catches it and breaks the loop. The failure itself is your exit condition.

That's Verse in a nutshell. Instead of bolting error-handling onto your control flow after the fact, failure is baked into the syntax from the start. It takes some rewiring of your instincts if you're used to true/false logic—but once you're fluent in it, you'll probably miss it when you go back to anything else.

Popular posts from this blog

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....

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 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...