swift学习笔记之基本数据类型-控制流

来源:互联网 发布:centos gcc 升级 编辑:程序博客网 时间:2024/04/30 13:19

1. 代码示例

//: Playground - noun: a place where people can playimport Cocoa//循环语句var words = ["A", "B", "C"]for letter in words{    print(letter)}for var i=0; i<words.count; i++ {    print(words[i])}print("\n")var i = 0, j = 5repeat{    print(i++)}while(i<j)print("\n")//条件语句var a = 0,b=3if(a>b){    print("a is greater than b")}else{    print("b is greater than a")}var d = 1switch(d){case 1:    print("1")case 2:    print("2")default:    print("nothing")}print("\n")//控制传递//1. switch默认带有break的效果//2. ffallthrough意味着将会执行完后面的case语句switch(d){    case 1:    print("1")    fallthrough    case 2:    print("2")    default:    print("nothing")}
2. 运行结果



0 0
原创粉丝点击