使用Scrollview-Swift时出错

使用Scrollview-Swift时出错,swift,loops,uiscrollview,Swift,Loops,Uiscrollview,我认为您希望使用for-In循环进行几次循环,但在代码中是这样使用的: var i in 1...4 { ... } 以下是您应该如何使用它: 您可以使用for-in循环来迭代序列,例如数字范围、数组中的项或字符串中的字符 此示例打印五倍表中的前几个条目: for index in 1...5 { print("\(index) times 5 is \(index * 5)") } // 1 times 5 is 5 // 2 times 5 is 10 // 3 times 5

我认为您希望使用for-In循环进行几次循环,但在代码中是这样使用的:

var i in 1...4 {
 ...
}
以下是您应该如何使用它:

您可以使用for-in循环来迭代序列,例如数字范围、数组中的项或字符串中的字符

此示例打印五倍表中的前几个条目:

for index in 1...5 {
    print("\(index) times 5 is \(index * 5)")
}

// 1 times 5 is 5
// 2 times 5 is 10
// 3 times 5 is 15
// 4 times 5 is 20
// 5 times 5 is 25
另一个例子:

let base = 3
let power = 10
var answer = 1
for _ in 1...power {
    answer *= base
}
print("\(base) to the power of \(power) is \(answer)")
// Prints "3 to the power of 10 is 59049"
还有一个:

let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names {
    print("Hello, \(name)!")
}
// Hello, Anna!
// Hello, Alex!
// Hello, Brian!
// Hello, Jack!
let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]
for (animalName, legCount) in numberOfLegs {
    print("\(animalName)s have \(legCount) legs")
}
// ants have 6 legs
// cats have 4 legs
// spiders have 8 legs
还有一个:

let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names {
    print("Hello, \(name)!")
}
// Hello, Anna!
// Hello, Alex!
// Hello, Brian!
// Hello, Jack!
let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]
for (animalName, legCount) in numberOfLegs {
    print("\(animalName)s have \(legCount) legs")
}
// ants have 6 legs
// cats have 4 legs
// spiders have 8 legs

Hi@Odusina Timilehin,欢迎来到stackoverflow,下面是如何提问stackoverflow问题的指南:请尝试@Odusina Timilehin下面我的答案中的代码。如果您发现我的答案或任何答案对您来说都是正确的,请以这种方式接受:。下次,请直接以文本形式发布您的代码和错误消息。欢迎,请接受我这样的回答: