无涯教程-Swift - repeat...while 循环函数

86 阅读1分钟

repeat.while循环类似于while循环,不同之处在于保证至少执行一次repeat.while循环。

repeat...while - 语法

SWIFT 4中repeat.while循环语法为-

repeat {
   statement(s);
} 
while( condition );

repeat...while - 流程图

Repeat-While Loops

repeat...while - 示例

var index=10

repeat {
   print( "Value of index is\(index)")
   index=index + 1
}
while index < 20

执行上述代码时,将生成以下结果-

Value of index is 10
Value of index is 11
Value of index is 12
Value of index is 13
Value of index is 14
Value of index is 15
Value of index is 16
Value of index is 17
Value of index is 18
Value of index is 19

参考链接

www.learnfk.com/swift/swift…