Consider the following code:
let value = "ABCDE"
for letter in value {
print(letter)
}
This prints:
A
B
C
D
E
Now consider the hypothetical code that when it finds a '2', it skips 2 forward in the loop. Here's pseudo-code showing what I'm asking...
let value = "AB2DE"
for letter in value {
if letter == "2" {
continue 2 <-- Does Swift support something similar to this?
}
print(letter)
}
The above would make the output look like this:
A
B
E
Note: Of course I can easily achieve this via managing a skip-counter, then using continue
, decrementing the counter as I go, or, if the source supports subscripting, as others have suggested I can use a while
loop where I manage my own index. There are a myriad ways to solve this hypothetical problem, but that's not the intent of my question.
My question is specifically to find out if the language natively supports skipping more than one iteration of a for-loop at a time (e.g. something like continueMany
or continue x
).