Color theme
0 day streak0 XPP1
SwiftLearn mode
MISSION 1 OF 1

Rotate the rehearsal queue

0 XP earned
Swift track: IntermediateMission: IntermediateArray queuesRemovalOptional fallback
Before you start this intermediate track

Functions and collections. Work with structs, mutable bindings, and optionals.

Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.

x
0 / 2 challenges
LEARN THE CONCEPT

Understand it, then try it.

A rehearsal queue uses an array to preserve performer order. removeFirst removes and returns the front element, and append moves that performer to the back. The first property is optional because an array could be empty. The fallback gives the display a sensible label if no performer is available. This example starts with a nonempty array. removeFirst() requires at least one element; the later fallback for first does not make removal safe on an empty array. Check isEmpty before removing from an array that might be empty.

Quest.swift
var performers = ["Oboe", "Cello", "Viola"]let finished = performers.removeFirst()performers.append(finished)let next = performers.first ?? "No performer"print(next)print(performers.count)

Run each mission independently as a Swift 5.9 or later script or playground. Top-level statements execute directly; these examples need only the Swift standard library and no Apple UI frameworks.

Track the values line by line. Predict the result before running this example in your own editor.