我是靠谱客的博主 明理手链,最近开发中收集的这篇文章主要介绍ios入门5_循环,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1.repeat while

import Cocoa
var index=15
repeat
{
print("index=(index)")
index+=1
}
while index<20

2.while

import Cocoa
var index=10
while index<20
{
print("index=(index)")
index+=1
}

3.continue
停止本次循环迭代,重新开始下一次循环迭代
和c++一样

import Cocoa
var index = 10
repeat{
index +=1
if( index == 15 ){ // index 等于 15 时跳过
continue
}
print( "index= (index)")
}while index < 20
//输出没有index=15

4.break
和c++一样

5.fallthrough
满足条件之后的所有case全部执行,无论是否匹配

import Cocoa
var index = 10
switch index {
case 100
:
print( "index 的值为 100")
fallthrough
case 10,15
:
print( "index 的值为 10 或 15")
fallthrough
case 5
:
print( "index 的值为 5")
default :
print( "默认 case")
}
输出为
index 的值为 100
index 的值为 5

6.for in

import Cocoa
for index in 1...5
{
print("(index)*5=/(index*5)")
}
import Cocoa
var someInts:[int]=[10,20,30]
for index in someints
{
print("index=/(index)")
}

最后

以上就是明理手链为你收集整理的ios入门5_循环的全部内容,希望文章能够帮你解决ios入门5_循环所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部