While Loop in Swift
Level 254 keystrokes
Counts down from 3 to 1 with a while loop, then prints "Go!" after the loop ends.
Swift code
// A var counter, since it changes in the loop1var n = 3// Repeats while n is positive2while n > 0 { // Prints 3, 2, 1 in turn3 print(n) // Decrease n by 1; without this the loop would never end4 n -= 15}// Runs once after the loop, when n is 0: Go!6print("Go!")Output
3 2 1 Go!
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Swift code and how often they appear.
"× 2(× 2)× 2=× 2-× 1!× 1{× 1}× 1>× 1