"One-sided form" 的 "half-open range operator"
"One-sided form" of the "half-open range operator"
来自 基本运算符 — Swift 编程语言 (Swift 4.2);
The half-open range operator also has a one-sided form that’s written
with only its final value. Just like when you include a value on both
sides, the final value isn’t part of the range. For example:
let names = ["Anna", "Alex", "Brian", "Jack"]
// Prints "Anna" and "Alex".
for name in names[..<2] {
print(name)
}
我的问题是; 第一个值 为什么我们不能也有这个?
// The next three lines are all valid.
var a = 0...
var b = ...0
var c = ..<0
// But this line is not, compilation error...
var d = 0<..
您的接线员不是正确的接线员:
var d = 0<.. /// Swift doesn't have this operator
如果你想要,你需要更多然后 0 然后使用下面:
var d = 1...
var d = 2...
var d = 3...
有关详细信息,您可以查看此 link:https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html
来自 基本运算符 — Swift 编程语言 (Swift 4.2);
The half-open range operator also has a one-sided form that’s written with only its final value. Just like when you include a value on both sides, the final value isn’t part of the range. For example:
let names = ["Anna", "Alex", "Brian", "Jack"]
// Prints "Anna" and "Alex".
for name in names[..<2] {
print(name)
}
我的问题是; 第一个值 为什么我们不能也有这个?
// The next three lines are all valid.
var a = 0...
var b = ...0
var c = ..<0
// But this line is not, compilation error...
var d = 0<..
您的接线员不是正确的接线员:
var d = 0<.. /// Swift doesn't have this operator
如果你想要,你需要更多然后 0 然后使用下面:
var d = 1...
var d = 2...
var d = 3...
有关详细信息,您可以查看此 link:https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html