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的更多相关文章

  1. 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 ...

  2. A Tour of Go Switch

    You probably knew what switch was going to look like. A case body breaks automatically, unless it en ...

  3. [ES7] Descorator: evaluated & call order

    When multiple decorators apply to a single declaration, their evaluation is similar to function comp ...

  4. 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 ...

  5. PHP资源列表

    一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...

  6. 【PHP资源】PHP 资源大全

    看到这篇文章不错,转来收藏 依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle ...

  7. Recover lost Confluence password

    confluence重置admin密码 复方法: 1. 运行此sql 找到你的管理员帐户: select u.id, u.user_name, u.active from cwd_user u joi ...

  8. 【PHP开发】国外程序员收集整理的 PHP 资源大全

    依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle:一个PHP扩展安装器 其他 ...

  9. python3.4 build in functions from 官方文档 翻译中

    2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python i ...

随机推荐

  1. PYTHON设计模式,创建型之简单工厂模式

    这个系统,感觉思路清爽,,相信多练练,多思考,就会熟悉的.. http://www.jianshu.com/p/2450b785c329 #!/usr/bin/evn python #coding:u ...

  2. hdu 3537 Daizhenyang's Coin 博弈论

    详见:http://www.cnblogs.com/xin-hua/p/3255985.html 约束条件6 代码如下: #include<iostream> #include<st ...

  3. [数论]ZOJ3593 One Person Game

    题意:一个人要从A走到B  只能走a布.b步.(a+b)步,可以往左或右走   问 最少要走几步,不能走到的输出-1 可以列出方程 $ax+by=A-B$ 或者 $ax+(a+b)y=A-B$ 或者 ...

  4. 李洪强iOS开发拓展篇—UIDynamic(重力行为+碰撞检测)

    iOS开发拓展篇—UIDynamic(重力行为+碰撞检测) 一.重力行为 说明:给定重力方向.加速度,让物体朝着重力方向掉落 1.方法 (1)UIGravityBehavior的初始化 - (inst ...

  5. MSSQLServer基础04(常用函数)

    类型转换函数 CAST ( expression AS data_type) CONVERT ( data_type, expression,[style]) 对日期的转换.转换成各种国家格式的日期. ...

  6. 113. Path Sum II

    题目: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the give ...

  7. ZOJ1586——QS Network(最小生成树)

    QS Network DescriptionIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature nam ...

  8. Android性能优化之如何避免Overdraw

    什么是Overdraw? Overdraw就是过度绘制,是指在一帧的时间内(16.67ms)像素被绘制了多次,理论上一个像素每次只绘制一次是最优的,但是由于重叠的布局导致一些像素会被多次绘制,而每次绘 ...

  9. 几种必知的oracle结构图

    一.数据库结构 二.Oracle 内存结构 三.进程结构 1. 用户进程:在数据库用户请求连接到Oracle 服务器时启动 2. 服务器进程:可以连接到Oracle实例,它在用户建立会话时启动 3. ...

  10. strlen的C/C+++实现

    2013-07-05 11:36:05 小结: 本函数给出了几种strlen的实现,有ugly implementation,也有good implementation.并参考标准库中的impleme ...