0x00 Lesson

If you put a loop inside a loop it’s called a nested loop, and it’s not uncommon to want to break out of both the inner loop and the outer loop at the same time.

As an example, we could write some code to calculate the times tables from 1 through 10 like this:

for i in 1...10 {for j in 1...10 {let product = i * jprint("\(i) * \(j) is \(product)")}
}

If we wanted to exit part-way through we need to do two things. First, we give the outside loop a label. like this:

outerLoop: for i in 1...10 {for j in 1...10 {let product = i * jprint("\(i) * \(j) is \(product)")}
}

Second, add our condition inside the inner loop, then use break outerLoop to exit both loops at the same time:

outerLoop: for i in 1...10 {for j in 1...10 {let product = i * jprint("\(i) * \(j) is \(product)")if product == 50 {print("It's a bullseye!")break outerLoop}}
}

With a regular break, only the inner loop would be exited - the outer loop would continue where it left off.


0x01 我的小作品

欢迎体验我的作品之一:小汉字-XHanzi
汉字书写入门,常用汉字 3800 个,二级字表 2200
App Store 搜索即可~


【Swift 60秒】33 - Exiting multiple loops相关推荐

  1. 【Swift 60秒】51 - Closures as parameters

    0x00 Lesson Because closures can be used just like strings and integers, you can pass them into func ...

  2. 【Swift 60秒】25 - The ternary operator

    0x00 Lesson Swift has a rarely used operator called the ternary operator. It works with three values ...

  3. 【Swift 60秒】80 - Classes: Summary

    0x00 Lesson You've made it to the end of the eighth part of this series, so let's summarize: Classes ...

  4. Linux 性能分析的前 60 秒

    Linux 性能分析的前 60 秒 为了解决性能问题,你登入了一台 Linux 服务器,在最开始的一分钟内需要查看什么? 在 Netflix 我们有一个庞大的 EC2 Linux 集群,还有非常多的性 ...

  5. ​【Python基础】告别枯燥,60 秒学会一个 Python 小例子(文末下载)

    本文推荐一个python的傻瓜式的学习资源,内容简单易懂,让人可以在60 秒学会一个 Python 小例子 当前库已有 300多 个实用的小例子 本文来源:https://github.com/jac ...

  6. Linux 入门必看:如何60秒内分析Linux性能

    作者:helightxu,腾讯 IEG 开发工程师 本文来自公众号:黑光技术 当你登陆一台 Linux 服务器之后,因为一个问题要做性能分析时:你会在第 1 分钟内做哪些检测呢? 在 Netflix, ...

  7. 解决 Linux 性能问题的前 60 秒

    2019独角兽企业重金招聘Python工程师标准>>> 为了解决性能问题,你登入了一台Linux服务器,在最开始的一分钟内需要查看什么? 在Netflix我们有一个庞大的EC2 Li ...

  8. 10行命令60秒快速定位性能瓶颈

    文章目录 综述 1. uptime 2. dmesg|tail 3. vmstat 1 每列的含义 4. mpstat -P ALL 1 5. pidstat 1 6. iostat -xz 1 7. ...

  9. python 每分钟运行一次_python 每60秒执行一次

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 我想在python上每60秒执行一次函数 我怎样才能异步做到这一点? impor ...

最新文章

  1. 使用PhoneGap开启移动开发之旅
  2. 如何通过在ViewPager中用手指轻扫来禁用分页,但是仍然能够以编程方式轻扫?
  3. flannel源码分析--RegisterNetwork
  4. 第四章使用jQuery操作DOM元素
  5. Android中的广播Broadcast详解
  6. 用C++实现十进制转二进制【个人思想】
  7. 什么是ip地址、子网掩码、网关和DNS?
  8. 【机器学习课程笔记(吴恩达)】1.2 什么是机器学习?
  9. php命令行(cli)下相对路径的问题
  10. 放大器非线性失真研究装置设计报告_活动 | 机电学子在2020年TI杯全国大学生电子设计竞赛中再创佳绩...
  11. TP框架多上传域上传图片
  12. python编程(redis操作)
  13. php漏洞黑掉数据库,WDCPnbsp;add_user.php任意数据库添加任意用户漏洞分析
  14. synchronized原理_面试必备—Synchronized 关键字使用、底层原理
  15. 组策略最佳实践之“降龙十八掌”
  16. 渗透测试学习 十六、 常见编辑器漏洞解析
  17. 集备二Linux部署之FTP
  18. 搭建你的Spring.Net+Nhibernate+Asp.Net Mvc 框架 (四)配置全攻略
  19. 基于SSM的企业人事人员管理系统
  20. STM32实现NRF24L01通信

热门文章

  1. Terramaster铁威马 F4-422真机实测预告 3000元级万兆4盘位NAS
  2. python txt文本特定字符串提取
  3. 使用mysqldump+WinRAR压缩备份数据库
  4. 在vue中,用路由router跳转打开一个新标签页
  5. MogaFX—ServiceNow的Bill McDermott正在关注货币汇率
  6. OCR之Tesseract安装
  7. Retinanet训练自己的数据(1):数据准备
  8. tc ebpf sample - tethering offload on linux pc
  9. 问题 A: 买牛奶  某同学负责给班里的同学买牛奶 ,每人两瓶。输入一个整数,表示班级人数。输出牛奶瓶数
  10. IPO并不遥远,飞哥IPERi模型助你打开互联网创业创新成功密码