swift 4上for循环的大于和小于等于

Bad*_*ath -2 for-loop swift

我们如何在swift for循环中实现<=和> =操作.我试过没有运气.

以下是我试过的选项

for i in 1..<=3{
   print(i)
}
Run Code Online (Sandbox Code Playgroud)

错误:使用未解析的运算符'.. <='for i in 1 .. <= 3 {

rob*_*off 10

您正在寻找"闭区域运营商".它是拼写...:

for i in 1 ... 3 {
    print(i)
}
Run Code Online (Sandbox Code Playgroud)

您可以Swift Programming Lanugage的 "Basic Operators"下阅读更多相关内容.


El *_*mer 6

在 C/Java 中:

for(int i=1 ; i<=3 ; i++)
    print(i)
Run Code Online (Sandbox Code Playgroud)

迅速:

for i in 1 ... 3 {
    print(i)
}
Run Code Online (Sandbox Code Playgroud)

在 C/Java 中:

for(int i=1 ; i<3 ; i++)
    print(i)
Run Code Online (Sandbox Code Playgroud)

迅速:

for i in 1 ..< 3 {
    print(i)
}
Run Code Online (Sandbox Code Playgroud)