Swift 循环for&while
来源:互联网 发布:淘宝如何编辑宝贝详情 编辑:程序博客网 时间:2024/05/12 12:18
Swift 循环for&while
Swift
中的循环和OC
中的循环“基本”一致for
while
do while
– >Swift
是repeat while
(do
用到异常处理机制
中去了)
常规写法
//其他点和if一样for var i = 0; i < 5; i++ { print(i)}
- Swift中的写法
//后面的 0..<5 称之为半闭区间//半闭区间的特点:包含头不包含尾for i in 0..<5 { print(i)}//闭区间特点:包含头包含尾//注意点:.../..< 中间不能有空格for i in 0...5 { print(i)}//忽略中间变量for _ in 0...5{ print("hello world")}
- 后面的
0..<5
称之为半闭区间
半闭区间
的特点
:- 包含头不包含尾
闭区间
的特点
:- 包含头包含尾
注意点:
.../..<
中间不能有空格
注意:
- 从
Swift 2.2
开始i++
系统提示需要使用i += 1
,在Swift 3
中会去掉++
写法 警告截图
从
Swift 2.2
开始for
常规写法( c语言类型写法)系统提示需要使用Swift
写法 在Swift 3
中会去掉常规写法- 警告截图
- 从
while Swift中很少使用while
var index = 0while index < 5{ print(index) index += 1}
repeat while
var i = 0repeat{ print(i) i += 1}while i < 5
0 0
- Swift 循环for&while
- swift 循环 for while
- swift while、do-while循环
- Swift笔记:For-In、While 循环、if条件语句
- Swift语法基础:17 - Swift的For循环, While, Do-While, If, Switch
- for循环while循环
- while循环、do..while 循环、for循环
- for循环,do....while循环,while循环
- for循环,while循环,do while循环
- while、do while、for循环
- 循环:for、while、do-while
- for /while 循环
- while/for 循环
- 跳出while/for循环
- while和for循环
- for while 循环语句
- python:循环(while、for)
- 循环结构while,for
- MySQL复合唯一索引分析
- Javascript中call的使用
- svn连接报错 Can't connect to host '*.*.*.*': 由于连接方在一段时间后没有正确答复或连接的主机没有响应,连接尝试失败。
- 每天一个命令(18)hostname
- vsftpd安装遇到问题及解决办法
- Swift 循环for&while
- 使用spring cache和ehcache之前必须了解的
- spring mvc 4.0 websocket 开发
- swiper的基础使用(十四)
- 欢迎使用CSDN-markdown编辑器
- WTL 如何获取OnMouseWheel 的鼠标信息
- 6-27背景流动的封装代码
- android-Camera.AutoFocusMoveCallback
- Python堆排序