xxxxxxxxxx
var x = 0;
while x < 10 {
print "\(x)" //prints x until x < 10 evaluates to false
x = x + 1
}
xxxxxxxxxx
// program to display numbers from 1 to 5
// initialize the variable
var i = 1, n = 5
// while loop from i = 1 to 5
while (i <= n) {
print(i)
i = i + 1
}
xxxxxxxxxx
var counter = 0
while true {
print("Counter is now \(counter)")
counter += 1
if counter == 556 {
break
}
}
xxxxxxxxxx
var number = 1
while number <= 20 {
print(number)
number += 1
}
print("Ready or not, here I come!")
xxxxxxxxxx
//aliceMessages is a huge array.
let character = "Caterpillar"
var index = Int()
var foundMessage = false
aliceMessages[index].
while !foundMessage && index < aliceMessages.count { //index of 0 means it starts at 0 and counts up
if aliceMessages[index].contains(character) {
foundMessage = true
print(index)
} else {
index += 1
}
}
xxxxxxxxxx
let cadence: Double = 180
var testSteps = 0
while testSteps < 10 {
print("take a step")
testSteps += 1
}
xxxxxxxxxx
// runs until some boolean expression is false
while booleanExpression {
//block of code to be executed...
}