Learn / Verse Basics Lesson 5 / 6

Control Flow: If Statements and Loops

In this lesson you'll learn to

  • Write an if/else statement in Verse that checks a player's score and triggers a game event
  • Use a loop in Verse to repeat an action a set number of times on your island
  • Explain in your own words what 'control flow' means using a real game example
  • Connect if statements and loops to real Fortnite island devices like Item Granters and Score Managers

🎮 What Is Control Flow?

Imagine you are playing a board game. You roll the dice. If you land on a red square, you lose a turn. Otherwise, you move ahead. The rules of the board game control what happens next.

In coding, control flow means: the order in which your code runs, and which parts it chooses to run. You are the rule-maker. You tell the computer, "Do THIS if something is true. Do THAT if it isn't."


🚦 If Statements — Your Game's Referee

An if statement is like a referee on your island. It watches what is happening. Then it makes a call.

Think of it like this:

If the player's score is 10 or more → open the treasure chest! Else → keep the chest locked.

The word if starts the check. The word else handles everything that is NOT true.

In Verse, it looks like this:

if (Score >= 10):
    # Do this when score is high enough
else:
    # Do this when score is too low
  • The stuff inside the if only runs when the condition is true.
  • The stuff inside the else runs when the condition is false.
  • Think of the condition like a yes/no question: "Is the score 10 or more?" Yes or no?

💡 New Word — Condition: A condition is a question that is either TRUE or FALSE. "Is it raining?" is a condition. "Is the player's score above 5?" is also a condition!


🔁 Loops — Your Island's Copy Machine

What if you wanted to give every player on your island 3 potions, one at a time? You could write the same line of code 3 times. But what if you wanted to do it 100 times? Writing 100 lines is no fun!

A loop is like a copy machine for your code. It runs the same instructions over and over until you say stop.

💡 New Word — Loop: A loop repeats a block of code. It's like pressing "replay" on a song, but for instructions.

Verse has a simple counting loop called a for loop. You tell it how many times to repeat. Here is the idea:

for (Index := 0..2):
    # This runs 3 times (0, 1, 2)

That 0..2 means "count from 0 up to and including 2." That is 3 counts total. Think of it as laps around a track: lap 0, lap 1, lap 2 — done!

🏃 Analogy: A for loop is like a coach yelling "Run 3 laps!" Your player runs one lap, then another, then another — and stops.


🧩 Putting It Together on Your Island

Let's say you are building a Score Challenge island. Here is the plan:

  • A player steps on a Trigger device.
  • Your Verse code checks: Did the player reach 5 points?
  • If yes → an Item Granter gives them a Legendary weapon. 🎉
  • If no → nothing special happens yet.
  • Also, when the game starts, a loop grants 3 common weapons to warm up the player.

You use an if statement for the score check. You use a loop for the weapon hand-out. Together, they make your island smart and fun!


🗂️ The Shape of Verse Code

Two things to always remember about Verse:

  1. Indentation matters. The code inside an if statement or loop must be indented (pushed in with spaces). This is how Verse knows which lines belong together.
  2. Colons start a block. After if(...) and for(...), you put a colon : and then indent the next lines.

Think of indentation like putting toys inside a box. The toys (code lines) belong to the box (if or loop) only if they are inside it.

Keep going — free

You've read the intro. The rest of this lesson — the worked example, the hands-on exercise, the quiz, and the recap — is free for members. Sign in to continue and track your progress.

New here? The whole Verse Basics track is free with a free account — sign in to start.

Pass the quiz above to chart this quest in your Journal.
Source
Verse Island

© Biloxi Studios Inc. — original Verse Island content.

Sources & licensing

Turn this into a guided course

Add Control Flow: If Statements and Loops to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.

🧭 The Keeper's log

Quest complete? Chart your next heading from the Verse Basics expedition.