The Switf programming Language 练习代码(2)

var n = 2; 
 
while n < 100
{
   n *= 2;
}

print(n);

// 在 swift 2.0 中,不再支持 do-while
// 不再支持 .. 和 ... 来表示范围

// 在循环中,使用 .. 来表示范围
/*var firstForLoop = 0;

for i in 0..3
{
   firstForLoop += i;
}

print(firstForLoop);
*/

// 函数和闭包

func greet(name: String, day: String) -> String
{
   return "Hello \(name), today is \(day).";
}

print(greet("Bob",day: "Tuesday")) // 第二个参数,需要写参数标签

// 练习6 删除 day 参数来表示今天吃了什么午饭

func greet1(name: String, day: String, lunch: String)->String
{
   return "Hello \(name),today is \(day),lunch is \(lunch).";
}

print(greet1("Tom", day: "TuseDay",lunch: "fish"));


你可能感兴趣的:(The Switf programming Language 练习代码(2))