美文网首页
03-Swift 循环的使用

03-Swift 循环的使用

作者: magic_pill | 来源:发表于2016-11-16 17:32 被阅读10次

一、for 循环的使用

  • 用法一:
//MARK : for 循环语句
for i in 1..<5{
    print(i)
}
  • 用法二:
//打印两遍 test,此时不需要创建变量 i
for _ in 1...2{
    print("test")
}

二、while 循环的使用

  • while 的一般使用
//MARK : while 循环
var i = 3
while i>0 {
    print(i)
    i-=1;
}
  • do...while 循环的使用
i = 10
repeat{
    print(i)
    i-=1
}while i>0
  • Swift3.0 中,do 为捕捉异常的关键字,而循环中的 do 改为 repeat。

相关文章

  • 03-Swift 循环的使用

    一、for 循环的使用 用法一: 用法二: 二、while 循环的使用 while 的一般使用 do...whil...

  • 流程控制与数组(控制循环结构)

    控制循环结构 使用break结束循环 使用continue结束本次循环 使用return结束循环

  • 原生JS实现阶乘

    使用递归 使用for循环 使用while循环

  • Swift 5.1 (5) - 控制流

    控制流 For-In循环 使用for-in循环迭代数组 使用for-in循环迭代字典 使用for-in循环迭代数值...

  • 数组循环方法

    for循环 使用break,可以中断循环 使用continue,循环可以继续 使用return,会报错 for.....

  • Scala编程详解

    1.7 条件控制与循环 scala没有for循环,只能使用while循环替代for循环,或者使用简易版for循环 ...

  • 循环的使用

    while循环的使用 代码块 for循环的使用 1,Python for循环可以遍历任何序列的项目,如一个列表或者...

  • for循环的使用

    for($i=0;$i<10;$i++){echo $i."";} 最前面表示初始化函数,中间为条件,后面为判断成...

  • for 循环的使用

    1、基本使用https://www.runoob.com/lua/lua-for-loop.html2、pairs...

  • python三大法器:生成器、装饰器、迭代器

    迭代器 迭代的概念 使用for循环遍历取值的过程叫做迭代,比如:使用for循环遍历列表获取值的过程 使用for循环...

网友评论

      本文标题:03-Swift 循环的使用

      本文链接:https://www.haomeiwen.com/subject/sfprpttx.html