Swift 3 While Statements
These are formatted so you can copy the code straight into your Swift Playground files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// The code would run this loop 100 times var i:Int = 0 while i < 100 { print(i) i += 1 //increment i so eventually we break out of the while loop } // while loops can also be used with non-numbers var title:String = "" //this loop will run 5 times while title != "aaaaa" { title = title + "a" //add another "a" each loop to the title } |
If you’re looking for places to learn after these Swift Playground examples, check out CartoonSmart.com or SpriteKitLessons.com