// loop statements
for var i = 0 ; i < 5 ; i++ {
Print("i = \(i)")
}
var j = 0
for j = 0; j <
Print("j = \(J)")
}
// for the first use of
//1. Traversing strings
let str = "Qwertyu"
for temp in str.characters {
Print("temp = \(temp)")
}
for Temp1 in 1... 6 {
Print("temp1 = \(temp1)")
}
//While statement
/*
format
While Boolean { }
description :
The while statement is stopped only if the Boolean value after the while is false, or the while statement is always executed
*/
var x = 0
while (x < 3)
{
Print("x = \(x)")
X + +
}
//Repeat while
/*
format:
Repeat {} while Boolean value
Description:
1: Execute Repeat statement now
2: Then execute while statement
3: Stop the repeat while statement if the Boolean value after the while statement is false , or the repeat while statement is executed all the time
*/
var y = 0
repeat {
y = y + 1
Print("y = \(y)")
}while (Y < 5)
Swift Loop Statements