1.while
import UIKit var a = 0 while (a<5) { print(a)//0,1,2,3,4 a+=1 }
2.repeat-while
就是其它语言中的do-while
import UIKit var a = 0 var b = true repeat{//先执行 print(a)//0,1,2,3,4,5 a+=1 if (a>5) { b=false } } while (b)//此时b=false,意味着不执行while()
2024-03-08 12:47:16
import UIKit var a = 0 while (a<5) { print(a)//0,1,2,3,4 a+=1 }
就是其它语言中的do-while
import UIKit var a = 0 var b = true repeat{//先执行 print(a)//0,1,2,3,4,5 a+=1 if (a>5) { b=false } } while (b)//此时b=false,意味着不执行while()