switch的用法
2016-01-28 14:45
316 查看
switch 支持任意类型的数据以及各种比较操作——不仅仅是整数以及测试相等。
let vegetable = "red pepper"
switch vegetable {
case "name":
let vegetableComment =
"Add some raisins and make ants on a log."
case
"cucumber", "watercress":
let vegetableComment =
"That would make a good tea sandwich."
case let x
where x.hasSuffix("pepper "):
let vegetableComment =
"Is it a spicy \(x)?"
default :
let vegetableComment =
"Everything tastes good in soup."
}
运行 switch 中匹配到的子句之后,程序会退出 switch 语句,并不会继续向下运行,所以不 需要在每个子句结尾写 break。
let vegetable = "red pepper"
switch vegetable {
case "name":
let vegetableComment =
"Add some raisins and make ants on a log."
case
"cucumber", "watercress":
let vegetableComment =
"That would make a good tea sandwich."
case let x
where x.hasSuffix("pepper "):
let vegetableComment =
"Is it a spicy \(x)?"
default :
let vegetableComment =
"Everything tastes good in soup."
}
运行 switch 中匹配到的子句之后,程序会退出 switch 语句,并不会继续向下运行,所以不 需要在每个子句结尾写 break。
相关文章推荐
- 微信朋友圈图片处理策略
- C操作内存函数(memset,memcpy,memcmp)
- 使用UISearchController 实现搜索框
- jQuery的deferred对象详解
- Linux学习之CentOS(二十)--CentOS6.4下修改MySQL编码方法
- 多列布局
- position:sticky 定位 position:fixed
- 个性签名
- c#版在pc端发起微信扫码支付
- View绘制流程简述
- HDU 1286 找新朋友 (欧拉函数_打表)
- 循环生成学号/
- EventBus详细解析
- IDA动态调试Android的DEX文件
- js对象或json对象深拷贝
- 通用的contain函数
- webpack 发布配置
- 使用nodejs,express,mysql,Bootstrap开发采购招标网站(三)Bootstrap-table实现Ajax删除数据
- js对象转json字符串,并保留js对象中的javascript脚本
- 测试必备技能系列1 :通过mysql命令进行脚本数据导入