ReferenceVerse

If Branching

if branching

Updated
Watch the Knot — if-branching in ~90 seconds.

One quick check at the market stall, and the customer walks away with a fresh Papaya instead of an empty crate.

Verse's if-statement checks for success, letting you safely grab an item from an array and bind it in the exact same breath.

We declare our stall's inventory, then use a failable if-condition to pull index one; if it exists, it binds to Snack and we print the success message, otherwise we fall back to the sold-out else branch.

Reach for failable if-branches whenever you need to safely unwrap an option or array lookup without crashing your game.

StallInventory := array{"Mango", "Papaya", "Coconut"}
if (Snack := StallInventory[1]):
    Print("Here is your {Snack}!")
else:
    Print("Sorry, we are sold out!")

Build your own lesson with if-branching

Generate a personalized, compile-checked lesson grounded in this exact reference.

Build a lesson →