A Tour of Go Switch evaluation order
Switch cases evaluate cases from top to bottom, stopping when a case succeeds.
(For example,
switch i {
case 0:
case f():
}
does not call f if i==0.)
Note: Time in the Go playground always appears to start at 2009-11-10 23:00:00 UTC, a value whose significance is left as an exercise for the reader.
package main import (
"fmt"
"time"
) func f(num *int) int{
(*num) = (*num) +
return (*num);
}
func main() {
num :=
total :=
switch total {
case f(&num):
fmt.Println(num)
case f(&num):
fmt.Println(num)
case f(&num):
fmt.Println(num)
}
fmt.Println("When's Saturday?")
today := time.Now().Weekday()
switch time.Saturday {
case today + :
fmt.Println("Today.")
case today + :
fmt.Println("Tomorrow.")
case today + :
fmt.Println("In tow days.")
default:
fmt.Println("Too far away.")
}
}
case中的语句可以是返回值的语句
A Tour of Go Switch evaluation order的更多相关文章
- A Tour of Go Switch with no condition
Switch without a condition is the same as switch true. This construct can be a clean way to write lo ...
- A Tour of Go Switch
You probably knew what switch was going to look like. A case body breaks automatically, unless it en ...
- [ES7] Descorator: evaluated & call order
When multiple decorators apply to a single declaration, their evaluation is similar to function comp ...
- Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide
Preface Validating data is a common task that occurs throughout all application layers, from the pre ...
- PHP资源列表
一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...
- 【PHP资源】PHP 资源大全
看到这篇文章不错,转来收藏 依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle ...
- Recover lost Confluence password
confluence重置admin密码 复方法: 1. 运行此sql 找到你的管理员帐户: select u.id, u.user_name, u.active from cwd_user u joi ...
- 【PHP开发】国外程序员收集整理的 PHP 资源大全
依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle:一个PHP扩展安装器 其他 ...
- python3.4 build in functions from 官方文档 翻译中
2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python i ...
随机推荐
- 【转】VC++消息钩子编程
VC++消息钩子编程
- c#基础精华01(强调代码规范,虚方法,抽象方法,接口)
强调代码规范 规则(法律,必须遵守否则报错) 语法 规范(道德,大家都喜欢有道德的人.) 注释//,/**/,/// 骆驼命名 :第一个单词首字母小写,之后的单词首字母大写 userName.user ...
- Unable to resolve target 'android-8'类似错误的解决办法
导入android项目出现:出现Unable to resolve target 'android-8'错误及其他的一些解决办法 - 为梦想而飞 - 博客频道 - CSDN.NEThttp://blo ...
- R语言学习笔记:数据的可视化
本文参考数据挖掘与R第二章节 读入数据 方法1,下载Data mining with r的配套包 install.packages('DMwR') 方法2,下载txt数据,并且读入数据.方法见上文. ...
- Oracle 列顺序测试
列顺序测试 大家在做表设计的时候通常对表中列的排列顺序没有过多注意,但是其实越常用的列,它的位置越靠前,则查询速度越快. 因为每个block里面存储了row directory (每行数据在块中的位移 ...
- LINQ语句
http://wenku.baidu.com/link?url=hPKqDWql7DNr6W2MsINakjRYYNXmXywB_U3h9FFMeFjcToYpusI2fYKgHjZSRq7r3ULG ...
- Flex 选项卡加载方式简介
Flex中选项卡默认只加载选中的选项,所以在初始化的时候给其他的选项卡中的对象赋值或是其他操作,都会出现空对象错误. 解决办法:给选项卡设置属性 creationPolicy=”all” 如:< ...
- linux0.11文件分析
在kernel包中有几个重要的文件夹和文件,他们各司其职,处理着有关内核的一些功能操作.其中文件夹有三个:blk_drv(块设备驱动),chr_drv(字符设备驱动),math(数学协处理器) 文件 ...
- IMX51启动模式
相关链接: http://blog.csdn.net/kickxxx/article/details/7236040 http://blog.csdn.net/evilcode/article/det ...
- poj 1039 Pipe(叉乘。。。)
题目:http://poj.org/problem?id=1039 题意:有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从 ...