Array Bounds Are Failable
Student can index arrays inside failure contexts and never write an out-of-bounds crash again.
array_bounds_are_failable in ~90 seconds.Your skiff bumps the third sea-stack pillar looking for a bonus flag that isn't there. Instead of crashing your entire island, Verse gracefully catches the miss and keeps the game running.
Array indexing in Verse is a failable expression, meaning it can succeed with a value or fail safely. It demands a failure context like an if block to handle missing elements without blowing up.
We declare our PillarScores array and target Index two, then wrap the lookup in an if assignment. If the pillar exists, we print the score, and if it’s out of bounds, the block simply skips.
Always reach for failure contexts whenever you index an array. It turns potential out-of-bounds crashes into safe, graceful skips.
PillarScores : []int = array{100, 200}
Index : int = 2
if (Score := PillarScores[Index]):
Print("Safe: {Score}")
Build your own lesson with array_bounds_are_failable
Generate a personalized, compile-checked lesson grounded in this exact reference.
Build a lesson →