Skip to content

Instantly share code, notes, and snippets.

@glowcap
Created January 18, 2018 04:26
Show Gist options
  • Select an option

  • Save glowcap/6309e502f6155c9ebaf684746f96d4fe to your computer and use it in GitHub Desktop.

Select an option

Save glowcap/6309e502f6155c9ebaf684746f96d4fe to your computer and use it in GitHub Desktop.
Example of using continue in a loop
import UIKit
let puzzleInput = "great minds think alike"
var puzzleOutput = ""
let charactersToRemove: [Character] = ["a", "e", "i", "o", "u", " "]
/// When using `continue` in an `if` statement (or switch) of a loop, the
/// loop immediately goes to the next iteration of the loop with completing
/// the rest of the current loop iteration.
/// This is different from a `break` that would simply end the loop.
/// If you run this example (adapted from The Swift Programming Language),
/// you'll see that when `continue` is hit, "contains vowels" is skipped.
for character in puzzleInput {
if charactersToRemove.contains(character) {
print("continue")
continue
} else {
puzzleOutput.append(character)
print("appended")
}
print("contains vowels")
}
print(puzzleOutput)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment