i have to modify my for loops of my swift 2 app. at the moment i use this syntax
for (var x = 0; x < 5; x++) {
i learned that i have to use this:
for x in 0..<5 {
but how i have to change this for loop:
for (var x = 0; x < 6; x = x+2) {
i have to modify my for loops of my swift 2 app. at the moment i use this syntax
for (var x = 0; x < 5; x++) {
i learned that i have to use this:
for x in 0..<5 {
but how i have to change this for loop:
for (var x = 0; x < 6; x = x+2) {
use stride
function
// for x<6
for i in 0.stride(to: 6, by: 2) {
print(i) // 0,2,4
}
//for x<=6
for i in 0.stride(through: 6, by: 2) {
print(i) // 0,2,4,6
}
In Easy way Try this,
var x = 0
for x in 0..<5 {
x += 2
}
print(x)
check this link for more reference Swift 2.2 tour