var result:Bool=true var loop:Int = 1 //條件式迴圈Conditional while result { print("success") loop++ if loop == 100 { break } }
2.do while loop
//do whele conditional do { }while result == false
3.for loop
var p:Int for p = 1 ; p <= 10 ; p++ { println(p) }
4. for in
//array 用中括號 var names=["allen","bill" , "candy" , "eric" , "frank"] //name不需要用var ,但在這裡name它還是區域變數 for name in names { print(name) }
5.for in 並不會給定變數初始值,以下這段CODE會出錯
沒有留言:
張貼留言