A concise, runnable Xcode playground exploring for, while, and repeat-while loops in Swift
Loops let you run a block of code repeatedly — over a range, over the elements of a collection, or until a condition changes. This is a small, self-contained Swift playground that demonstrates the three core looping constructs in Swift and can be run directly in Xcode to see the printed output.
It is meant as a concise learning example, not a library or app.
for-inover a range — iterating a closed range (9...15) and printing each index.for-inover a collection — looping through the elements of an array of strings.for-inover a string — iterating each character of aString.for-inover a numeric array — visiting each element of[Int].whileloop — repeating while a condition holds, incrementing a counter until it exits.repeat-whileloop — running the body at least once before evaluating the condition.
git clone https://github.com/ahmetbostanciklioglu/Loops.git
cd LoopsUnzip Loops.playground.zip, open Loops.playground in Xcode, and run it to view the results in the console and the results sidebar.
- Xcode 12 or later
- Swift 5
- macOS with the iOS playground platform
Ahmet Bostancıklıoğlu — @ahmetbostanciklioglu · ahmetbostancikli@gmail.com
⭐ If this helped you, consider giving the repo a star!