Swift Module 2 – Basics: values, types, operators and control flow
Loops, labels and control transfer
Loop in Swift with for-in over ranges and collections, write while and repeat-while loops that end, and steer nested loops with break, continue and labels.
What you will learn
- Iterate with for-in over ranges, strides, arrays, strings and dictionaries, with enumerated(), zip and indices
- Choose between while and repeat-while, and write loops whose exit condition is always reached
- Use continue and break to control a loop, and statement labels to control nested loops
- Remove items from an array without skipping any or reading past its end
Before you start
What you’ll learn · Before you start
What you will learn
- Iterate with for-in over ranges, strides, arrays, strings and dictionaries, with enumerated(), zip and indices
- Choose between while and repeat-while, and write loops whose exit condition is always reached
- Use continue and break to control a loop, and statement labels to control nested loops
- Remove items from an array without skipping any or reading past its end
Before you start
On this page
Four coaches of four seats are 16 seats to check for the first free window seat, and the search in this lesson finds
one after looking at 8 of them. Let its break end only the inner loop and it keeps going: it looks at 10 seats and
reports three seats in three coaches, when one was asked for.
Here you will loop over ranges, strides, arrays, strings and dictionaries with for-in, number and pair items with
enumerated() and zip, write while and repeat-while loops that are sure to end, skip passes with continue
and stop with break, reach an outer loop with a label, and remove items from an array without the loop going wrong.
for-in takes each item of a sequence in turn
for i in 1...5 runs its body five times, with i holding 1, then 2, up to 5. The same statement walks through an
array’s items, a string’s characters, a stride’s steps or a dictionary’s pairs of key and value: anything that is a
sequence: A type whose values a for-in loop can walk through one at a time, such as an array, a range, a stride or a string: a type that conforms to the Sequence protocol.. This program prints part of the 7 times table, adds up three fares, spells out a
string, lists departures every 15 minutes, repeats a step three times and prints a dictionary:
// for_in.swift: one loop statement, six kinds of sequence.
for i in 1...5 {
print("7 x \(i) = \(7 * i)")
}
let fares = [20, 35, 50]
var total = 0
for fare in fares {
total += fare
}
print("total fare:", total)
var spelled = ""
for letter in "PNR" {
spelled += "\(letter)."
}
print(spelled)
for minute in stride(from: 0, to: 60, by: 15) {
print("departure at 6:\(minute < 10 ? "0" : "")\(minute)")
}
var stars = ""
for _ in 1...3 {
stars += "*"
}
print(stars)
let platforms = ["Thane": 4, "Dadar": 3, "Kurla": 1]
for station in platforms.keys.sorted() {
print(station, "platform", platforms[station] ?? 0)
} Output
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 total fare: 105 P.N.R. departure at 6:00 departure at 6:15 departure at 6:30 departure at 6:45 *** Dadar platform 3 Kurla platform 1 Thane platform 4
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O for_in.swift -o for_in && ./for_in
i, fare, letter and minute are constants that the loop declares itself and sets at the start of every pass; the
body can read them but not change them. When the items themselves do not matter, _ takes their place, as in
for _ in 1...3, which only repeats the body. Step through how the first loop gets its numbers:
The drawing shows the whole scene; its 6 steps are listed below.
Every step as text
- Start the loop. The loop calls makeIterator() on the range 1...5, once. The iterator remembers where it is in the range, so the code needs no counter of its own.
- The first item. next() returns Optional(1). It is not nil, so the loop gives the 1 to i and runs the body, which prints "7 x 1 = 7".
- The next pass. Back at the top, next() returns Optional(2), and the body prints "7 x 2 = 14". i is a new constant on every pass; the body cannot change it.
- The last item. Passes 3 and 4 go the same way. On the fifth, next() returns Optional(5), and the body prints "7 x 5 = 35".
- Nothing left. The sixth call of next() returns nil, because the range has no more numbers. The loop does not run the body again; the program goes on with the line after the loop.
- The same for every sequence. An array gives its items in order, a string its characters, a stride its steps, and a dictionary its keys and values, in no fixed order. Each answers next() until it runs out.
The loop calls makeIterator() on the range once and then asks its iterator: The value a for-in loop gets by calling makeIterator() on a sequence. The loop asks it for each next item with next(), which returns nil when there are none left. for one item
at a time with next(). An item comes as an optional: a value runs the body once more, and nil ends the loop.
A dictionary has no order of its own, and Swift does not promise the same order from one run of a program to the
next. That is why for_in.swift loops over platforms.keys.sorted(), the keys in alphabetical order, and looks each
one up with ?? 0, since a lookup returns an optional.
Printing a dictionary in the order of a loop
for (station, platform) in platforms gives every pair, but in an order that can change between runs, so output
that depends on it cannot be tested. Sort the keys first, as for_in.swift does, whenever the order shows.
Checkpoint
Check: One item per pass of for-in
enumerated(), zip and indices add numbers and partners
Three helpers cover the common cases of needing more than the item. enumerated() pairs each item with a count from
0, zip walks two sequences side by side, and indices gives the positions of an array. This program uses all three
on four stops of a train line, with travel times from this example’s own timetable:
// positions.swift: numbers with enumerated(), partners with zip, and positions with indices.
let stops = ["Churchgate", "Dadar", "Bandra", "Andheri"]
for (number, stop) in stops.enumerated() {
print(number + 1, stop)
}
let minutes = [0, 14, 22]
for (stop, minute) in zip(stops, minutes) {
print("\(stop) at +\(minute) min")
}
for i in stops.indices where i > 0 {
print(stops[i - 1], "->", stops[i])
} Output
1 Churchgate 2 Dadar 3 Bandra 4 Andheri Churchgate at +0 min Dadar at +14 min Bandra at +22 min Churchgate -> Dadar Dadar -> Bandra Bandra -> Andheri
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O positions.swift -o positions && ./positions
enumerated() gives a pair on each pass, the count first and then the item, and the loop takes the pair apart into
number and stop; number + 1 makes the list start at 1. The zip loop printed three lines, not four. Step
through it:
The drawing shows the whole scene; its 5 steps are listed below.
Every step as text
- Two arrays, side by side. zip(stops, minutes) walks through both arrays at once. stops has four items and minutes, in this example's timetable, three.
- First pair. The first pass takes the first item of each, ("Churchgate", 0), and the loop names them stop and minute. It prints "Churchgate at +0 min".
- Second and third pairs. The next two passes pair Dadar with 14 and Bandra with 22, always the items at the same position of the two arrays.
- One side runs out. For a fourth pair, zip asks minutes for a fourth item and gets none. The loop ends at once, without an error, after three passes.
- Andheri is left out. The sequence zip makes is as long as the shorter array, so Andheri is never paired and never printed. When two arrays must match, compare their counts before the loop.
zip makes a sequence as long as the shorter of its two inputs, so Andheri, which has no time, was dropped without an
error. The last loop needs positions, because each pass looks at the item before as well, and where i > 0 skips the
first position, which has no item before it. A where clause on a for runs the body only for the items that pass
its condition.
Take positions from indices
stops.indices gives exactly the positions a collection has. A slice such as stops[1...] keeps the positions it
had in stops, 1 to 3, so the counts of enumerated(), 0 to 2, and a range 0..<count both miss them, while its
indices does not.
Checkpoint
Check: enumerated(), zip and indices
while tests before each pass, repeat-while after it
A while loop is for work whose number of passes is not known in advance. This program adds up the digits of 4096 by
taking the last digit with % 10 and dropping it with /= 10 until nothing is left, then counts digits in two ways:
// digits.swift: while checks before each pass, repeat-while after it.
var n = 4096
var sum = 0
while n > 0 {
sum += n % 10
n /= 10
}
print("digit sum of 4096:", sum)
func digitsWhile(_ value: Int) -> Int {
var rest = value
var count = 0
while rest > 0 {
count += 1
rest /= 10
}
return count
}
func digitsRepeat(_ value: Int) -> Int {
var rest = value
var count = 0
repeat {
count += 1
rest /= 10
} while rest > 0
return count
}
print("digits of 4096:", digitsWhile(4096), "with while,", digitsRepeat(4096), "with repeat-while")
print("digits of 0:", digitsWhile(0), "with while,", digitsRepeat(0), "with repeat-while") Output
digit sum of 4096: 19 digits of 4096: 4 with while, 4 with repeat-while digits of 0: 0 with while, 1 with repeat-while
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O digits.swift -o digits && ./digits
while rest > 0 tests its condition before every pass, the first one too, so its body may run zero times.
repeat { … } while rest > 0 runs the body first and tests afterwards, so its body always runs at least once. For
4096 both counts are 4, but for 0 the while version says 0 digits and the repeat-while version says 1, which is
right. Step through both for the value 0:
The drawing shows the whole scene; its 6 steps are listed below.
Every step as text
- digitsWhile(0). A while loop tests its condition before every pass, the first one included. rest is 0, and 0 > 0 is false.
- The body never runs. The loop ends before its first pass, so count stays 0 and digitsWhile(0) returns 0. But 0 is written with one digit.
- digitsRepeat(0). A repeat-while loop runs its body first and tests afterwards. count becomes 1, and rest becomes 0 / 10, which is 0.
- The test comes after. Now 0 > 0 is false, so the loop stops after its one pass. digitsRepeat(0) returns 1, the right answer.
- For 4096 they agree. For 4096 both loops make four passes, rest going 409, 40, 4 and 0, and both return 4. They differ only when the body would run zero times.
- Choose by the first pass. Use repeat-while when the body must run at least once, as for the digits of a number. Use while when zero passes can be right, as for the digit sum of 0.
A loop like these ends only if each pass moves its condition towards false. Here every pass divides rest by 10, and
an integer above 0 divided by 10 again and again reaches 0. Write the exit condition first, then check that every
path through the body moves towards it.
An update that a path can skip
In while rest > 0 { if rest % 2 == 0 { rest /= 10 } } an odd rest never changes, so the loop never ends. Put
the update where every pass runs it, or make every branch change the condition’s value.
Checkpoint
Check: while and repeat-while
continue skips the rest of a pass, break ends the loop
continue ends the current pass and starts the next one; break ends the whole loop, and the program goes on after
it. This loop adds fares up to a limit of 500, skipping refunds, which are negative, and stopping before the fare that
would take the total past the limit:
// fare_limit.swift: continue skips the rest of a pass, break ends the loop.
let fares = [120, -40, 250, 90, 310, 75] // a negative fare is a refund
let limit = 500
var total = 0
for fare in fares {
if fare < 0 {
continue // a refund is not a spend: go to the next fare
}
if total + fare > limit {
break // this fare would pass the limit: stop adding
}
total += fare
print("added \(fare), total \(total)")
}
print("spent \(total) of \(limit)")
var spends = 0
for fare in fares where fare > 0 {
spends += 1
}
print("fares that are spends:", spends)
let platforms = [Int("3"), Int("TBA"), Int("1")]
for case let platform? in platforms {
print("announced: platform \(platform)")
} Output
added 120, total 120 added 250, total 370 added 90, total 460 spent 460 of 500 fares that are spends: 5 announced: platform 3 announced: platform 1
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O fare_limit.swift -o fare_limit && ./fare_limit
Step through the first loop’s six fares:
The drawing shows the whole scene; its 5 steps are listed below.
Every step as text
- 120. 120 is not a refund, and 0 + 120 does not pass 500, so it is added. The total is 120.
- -40, a refund. -40 < 0, so continue runs. The rest of this pass is skipped, the total stays 120, and the loop goes straight to the next fare.
- 250 and 90. Both are spends that fit under the limit, so the total grows to 370 and then 460.
- 310 would pass the limit. 460 + 310 = 770, which is more than 500, so break runs. The loop ends at once: 310 is not added, and the last fare, 75, is never even looked at.
- Two exits, two meanings. continue ends only the current pass, so the loop goes on with the next fare. break ends the whole loop, so the program goes on after it.
The refund of −40 was skipped by continue, the total reached 460, and 310 would have made it 770, so break ended
the loop. The last fare, 75, was never looked at, even though it would have fitted: a break stops the loop, not just
one fare. The second loop counts the spends with for fare in fares where fare > 0, a where clause that does what
an if … continue at the top of the body would. The last loop is a preview of the module on pattern matching:
for case let platform? in platforms runs only for the optionals that hold a value, here 3 and 1, and skips the nil.
Key idea
continue leaves the current pass and the loop goes on; break leaves the loop. A condition for skipping can also
sit on the loop itself, as a where clause.
Checkpoint
Check: continue and break
A label lets break and continue reach an outer loop
A break inside a nested loop ends only the innermost loop it is in. To find the first free window seat in four
coaches, the search must stop both the seat loop and the coach loop. This program runs the search twice, once with a
plain break and once with a statement label: A name and a colon before a loop, if or switch, as in search: for coach in …, so that break search or continue search inside a nested loop acts on that statement., search:, in front of the outer loop
and break search inside:
// seat_search.swift: the first free window seat, without a label and with one.
let window = [true, false, false, true] // seats 1 and 4 of every coach are at a window
let taken = [
[true, false, false, true], // coach 1: both window seats taken
[true, true, false, false], // coach 2: seat 4 is free
[false, true, true, true], // coach 3: seat 1 is free
[false, false, true, true], // coach 4: seat 1 is free
]
var checks = 0
print("Without a label:")
for coach in 0..<taken.count {
for seat in 0..<window.count {
checks += 1
if !window[seat] {
continue
}
if !taken[coach][seat] {
print(" coach \(coach + 1), seat \(seat + 1)")
break // leaves the seat loop only
}
}
}
print(" \(checks) seats looked at")
checks = 0
print("With a label:")
search: for coach in 0..<taken.count {
for seat in 0..<window.count {
checks += 1
if !window[seat] {
continue
}
if !taken[coach][seat] {
print(" coach \(coach + 1), seat \(seat + 1)")
break search // leaves both loops
}
}
}
print(" \(checks) seats looked at") Output
Without a label: coach 2, seat 4 coach 3, seat 1 coach 4, seat 1 10 seats looked at With a label: coach 2, seat 4 8 seats looked at
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O seat_search.swift -o seat_search && ./seat_search
Without the label, break left the seat loop only, so the coach loop went on to coaches 3 and 4 and found a seat in
each: three seats, 10 looked at. With break search, both loops stopped at coach 2, seat 4, after 8. Step through the
labelled search:
The drawing shows the whole scene; its 5 steps are listed below.
Every step as text
- Coach 1. The outer loop takes coach 1 and the inner loop its four seats. Seats 1 and 4 are window seats but taken, and seats 2 and 3 are aisle seats, which continue skips.
- On to coach 2. The inner loop has run out of seats, so the outer loop takes its next coach. The count of seats looked at is 4 so far.
- Seat 4 is free. Seat 1 of coach 2 is a taken window seat, seats 2 and 3 are aisle seats, and seat 4 is a free window seat, after 8 seats in all. The program prints "coach 2, seat 4".
- break search. break search ends the loop labelled search, the outer one, so both loops stop at once. Coaches 3 and 4 are never looked at, and the program prints "8 seats looked at".
- Without the label. A plain break ends only the innermost loop, the seat loop. The coach loop would go on to coaches 3 and 4, find a seat in each, and print three seats after 10 looked at.
continue takes a label in the same way. continue search would end the current pass of the coach loop and go on
with the next coach, skipping the coach’s remaining seats, which is how a search moves past a coach that is closed.
Labels can also name an if or a switch for break, and every label in a nest must be different. The Swift
Programming Language notes that a label does no harm where a plain continue would act on the right loop anyway, and
that it can make the logic clearer to read.
Checkpoint
Check: Labels on nested loops
Change an array after the loop, not under its positions
A for-in loop over an array reads the array as it was when the loop began. Arrays are values: the loop keeps the
array it was given at the start, and a change in the body goes to the variable, not to the array the loop is reading.
This program appends inside such a loop, and then removes items by building a new array:
// own_copy.swift: a for-in loop reads the array as it was when the loop began.
var queue = ["PNR41", "PNR57"]
for booking in queue {
queue.append(booking + "-return")
}
print(queue)
var bookings = ["PNR41", "CANCELLED", "CANCELLED", "PNR57", "PNR63"]
var kept: [String] = []
for booking in bookings where booking != "CANCELLED" {
kept.append(booking)
}
bookings = kept
print(bookings) Output
["PNR41", "PNR57", "PNR41-return", "PNR57-return"] ["PNR41", "PNR57", "PNR63"]
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O own_copy.swift -o own_copy && ./own_copy
The loop over queue ran twice, not forever, although it appended two items: it read the two-item array it started
with. Removing by position is different, because a range of positions such as 0..<bookings.count is worked out once,
before the first pass, and a removal moves every later item up one place:
// remove_by_index.swift: removing items inside a loop over the positions the array had at the start.
var bookings = ["PNR41", "CANCELLED", "CANCELLED", "PNR57", "PNR63"]
for i in 0..<bookings.count {
print("checking position", i)
if bookings[i] == "CANCELLED" {
bookings.remove(at: i)
}
}
print(bookings) from session import run, version
# remove_by_index.swift in a debug build and in a release build.
version()
run("""
swiftc -Onone remove_by_index.swift -o remove_by_index
!./remove_by_index
swiftc -O remove_by_index.swift -o remove_by_index
!./remove_by_index
""") Output
# Apple Swift version 6.4 (swiftlang-6.4.0.34.1) $ swiftc -Onone remove_by_index.swift -o remove_by_index $ ./remove_by_index checking position 0 checking position 1 checking position 2 checking position 3 checking position 4 Swift/ContiguousArrayBuffer.swift:692: Fatal error: Index out of range [exit status 133] $ swiftc -O remove_by_index.swift -o remove_by_index $ ./remove_by_index checking position 0 checking position 1 checking position 2 checking position 3 checking position 4 [exit status 133]
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 remove_session.py
Both builds stopped with exit status 133 after checking position 4. Step through what happened to the positions:
The drawing shows the whole scene; its 7 steps are listed below.
Every step as text
- The range is fixed. for i in 0..<bookings.count works out the range once, before the first pass: 0..<5, positions 0 to 4. Removing items later does not shorten it.
- i = 0. Position 0 holds PNR41, which stays.
- i = 1, a removal. Position 1 holds CANCELLED, so remove(at: 1) runs. Every item after it moves up one place: the second CANCELLED is now at position 1, PNR57 at 2, PNR63 at 3, and position 4 is empty.
- i = 2 skips one. The loop reads position 2, PNR57. The second CANCELLED moved into position 1, which the loop has already passed, so it is never checked.
- i = 3. Position 3 holds PNR63, which stays. The array now has four items, at positions 0 to 3.
- i = 4 traps. The range still gives 4, but no position 4 is left. bookings[4] stops the program with "Index out of range", exit status 133.
- The fix. Build a new array of the items to keep, as own_copy.swift does with for … where, or call removeAll(where:). Neither reads positions that the removals move.
The second CANCELLED moved into position 1, which the loop had passed, so it was never checked, and the range still
offered position 4 after the array had shrunk to four items. Reading bookings[4] was a
trap: An immediate stop of a program at a failed runtime check, such as an integer overflow or a division by zero. No line after it runs; a shell reports the stop as an exit status of 128 plus the signal's number. More in “Integers, overflow traps and wrapping operators”: Swift checks every index and stops the program rather than read outside an array. Build a
new array of the items to keep, as own_copy.swift does with for booking in bookings where booking != "CANCELLED",
or call bookings.removeAll(where:), which the module on closures covers.
Checkpoint
Check: Changing an array while looping
Practise: the first repeated booking and the primes up to n
Write two functions. firstRepeat(_:) takes booking IDs in the order they arrived and returns the first ID that
appears a second time, or nil when none does; use a loop over the positions and an inner loop over the earlier ones.
primes(upTo:) returns the primes up to a limit: for each number from 2, try to divide it by the primes found so far,
skip to the next number at the first divisor, and stop trying once a prime’s square passes the number. Return an empty
array for a limit below 2, because 2...1 is not a valid range.
Write and test yours before reading this version:
// practice.swift: the first repeated booking and the primes up to a limit.
func firstRepeat(_ ids: [String]) -> String? {
for i in ids.indices {
for j in 0..<i where ids[j] == ids[i] {
return ids[i]
}
}
return nil
}
func primes(upTo limit: Int) -> [Int] {
guard limit >= 2 else {
return []
}
var found: [Int] = []
candidates: for n in 2...limit {
for p in found {
if p * p > n {
break // no divisor up to the square root: n is prime
}
if n % p == 0 {
continue candidates // a divisor: try the next n
}
}
found.append(n)
}
return found
}
print(firstRepeat(["PNR41", "PNR57", "PNR63", "PNR57", "PNR41"]) ?? "none")
print(firstRepeat(["PNR41", "PNR57"]) ?? "none")
print(primes(upTo: 30))
print(primes(upTo: 1)) Output
PNR57 none [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] []
Recorded with Apple Swift 6.4 (swiftlang-6.4.0.34.1) on macOS 26 arm64. To run it yourself: swiftc -O practice.swift -o practice && ./practice
firstRepeat(_:) returns from inside both loops, which ends them at once, as a labelled break would. primes(upTo:)
needs both kinds of jump: break in the inner loop once no divisor is possible, and continue candidates, with a
label, to leave the inner loop and move the outer loop to its next number at the first divisor. Finish with the
practice round below. It asks first about the part of this lesson you have missed most often, and raises the level
as your answers improve:
Practice that adapts to you
Practise this lesson
12 questions about 6 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.
Interview questions
Warm-up: what is the difference between while and repeat-while in Swift?
A while loop tests its condition before every pass, so its body can run zero times; a repeat-while loop runs its
body first and tests afterwards, so the body runs at least once. Swift’s repeat-while is what other languages call
do-while. The choice matters exactly when the condition is false from the start. Counting the digits of a number
by dividing it by 10 shows it: for 0, a while loop makes no pass and answers 0, while repeat-while makes one pass
and answers 1, which is right. Use repeat-while when one pass must always happen, such as asking for input until it
is valid, and while when no pass at all can be the right result. In both, every pass has to move the condition towards
false, or the loop never ends.
Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.
-
Fresher to mid
A clean-up job runs for i in 0..<bookings.count and calls bookings.remove(at: i) for each cancelled booking. It stops with Index out of range, and a version that first checks i < bookings.count no longer stops but leaves some cancelled bookings behind. Explain both symptoms with a small example, and give two correct ways to remove them.
-
Fresher to mid
A seat search loops over 20 coaches of 72 seats, collects every free window seat it meets and then uses only the first. How many seats does it look at when the first free window seat is coach 2, seat 10? How would you make it stop at the first match, with a label and without?
Key takeaways
for-inwalks any sequence, a range, a stride, an array, a string or a dictionary, by asking its iterator for one item at a time until it gives nil; sort a dictionary’s keys first whenever the order shows.enumerated()pairs items with a count from 0,zippairs two sequences and stops at the shorter one, andindicesgives an array’s positions.whiletests before each pass and may run zero times,repeat-whiletests after and runs at least once, and in both every pass must move the condition towards false.continueends the current pass andbreakthe whole loop, and awhereclause on aforloop filters its items.- A plain
breakorcontinueacts on the innermost loop; a statement label such assearch:lets them act on an outer loop. - A
for-inloop over an array reads the array as it began, but removing items inside a loop over0..<countskips items and then traps, so build a new array or useremoveAll(where:).
Terms in this lesson
- iterator
- The value a for-in loop gets by calling makeIterator() on a sequence. The loop asks it for each next item with next(), which returns nil when there are none left.
- sequence
- A type whose values a for-in loop can walk through one at a time, such as an array, a range, a stride or a string: a type that conforms to the Sequence protocol.
- statement label
- A name and a colon before a loop, if or switch, as in search: for coach in …, so that break search or continue search inside a nested loop acts on that statement.
References
- The Swift Programming Language (6.4): Control Flow (Swift.org)
- The Swift Programming Language (6.4): Statements, Loop Statements and Control Transfer Statements (Swift.org)
- Sequence: enumerated() (Swift.org)
- zip(_:_:) (Swift.org)
- Array: Accessing Array Values and Modifying Copies of Arrays (Swift.org)
- IndexingIterator (Swift.org)
- Array: remove(at:) (Swift.org)
- Array: removeAll(where:) (Swift.org)
Report a problem with this lesson
Kept only in this browser. Your Learn progress