「swift2.0」repeat 和 for in 迴圈
repeat 跟C++的do-while 粉像的說
int i = 0;
do{
cout<<i<<endl;
}while(i<100);
寫成swift的repeat就是
int i = 0;
do{
cout<<i<<endl;
}while(i<100);
寫成swift的repeat就是
var i = 0
repeat {
i++
print(i)
} while i < 100
for in 加上SQL語法where
迴圈+查詢語法 = 無敵
var scores = [ 10 , 20 , 30 , 40 ,50 ,60, 70]
for score in scores where score <= 30 {
print(score)
}
結果印出小於或等於30的分數^o^