语法
在 Swift 编程语言中的 do...while 语法如下:
do
{
statement(s);
}while( condition );
应当指出的是,条件表达式出现在循环的底部,所以在测试条件之前循环语句执行一次。如果条件为真,控制流跳回起来继续执行,循环语句再次执行。重复这个过程,直到给定的条件为假。
数字 0,字符串 “0” 和 “” ,空列表 list(),和 undef 全是假的在布尔上下文中,除此外所有其他值都为 true。否定句一个真值 !或者 not 则返回一个特殊的假值。
流程图
实例
复制代码import Cocoa
var index = 10
do{
println( "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
注:相关教程知识阅读请移步到swift教程频道。









