Switch cases evaluate cases from top to bottom, stopping when a case succeeds.

(For example,

  1. switch i {
  2. case 0:
  3. case f():
  4. }

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.

  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "time"
  6. )
  7.  
  8. func f(num *int) int{
  9. (*num) = (*num) +
  10. return (*num);
  11. }
  12. func main() {
  13. num :=
  14. total :=
  15. switch total {
  16. case f(&num):
  17. fmt.Println(num)
  18. case f(&num):
  19. fmt.Println(num)
  20. case f(&num):
  21. fmt.Println(num)
  22. }
  23. fmt.Println("When's Saturday?")
  24. today := time.Now().Weekday()
  25. switch time.Saturday {
  26. case today + :
  27. fmt.Println("Today.")
  28. case today + :
  29. fmt.Println("Tomorrow.")
  30. case today + :
  31. fmt.Println("In tow days.")
  32. default:
  33. fmt.Println("Too far away.")
  34. }
  35. }

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. Java的ResultSet中rs.next()含义

  2. Oracle10g 回收站及彻底删除table : drop table xx purge

    drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 1.通过查询回收站user_recyclebin获取被删除的表信息, ...

  3. python调试 设置断点

    1在所需要调试的地方加入如下代码: import pdb    pdb.set_trace() 2调试代码常用命令: 实例请见参考文献: 1http://www.cnblogs.com/qi09/ar ...

  4. 【HDOJ】4579 Random Walk

    1. 题目描述一个人沿着一条长度为n个链行走,给出了每秒钟由i到j的概率($i,j \in [1,n]$).求从1开始走到n个时间的期望. 2. 基本思路显然是个DP.公式推导也相当容易.不妨设$dp ...

  5. git删除中文文件

    git中出现如下代码时,是因为文件中包含中文.而且我们也无法用 git rm name 命令来删除该文件. deleted: "chrome_plugin/source_file/iHub\ ...

  6. 1306.Sequence Median(堆排序)

    1306 URAL真是没水题 以为简单的排序就好了 ME  内存限制很紧 堆排序 或者 STL 用堆排序做的 正好复习一下 都忘了 #include <iostream> #include ...

  7. 大四实习准备3_java多线程

    4.25.27无耻地懒散了.....26号陪女朋友去了.今天28号,继续加油! 2015-4-28 Java 多线程 (java中类不能多继承,可以多层继承:接口则都可以) 定义和创建: 方法一:继承 ...

  8. 结构体UT_LIST_ADD_LAST

    使用 UT_LIST_ADD_LAST(list, buf_pool->free, (&block->page)); /****************************** ...

  9. php 生成类的对象 $a=new test();

    程序 <?php class test { ... } $a=new test(); 1.BNF 范式 start: variable '=' expr ';' expr: new_expr ; ...

  10. IDE模式下安装Windows 7强行改回ACHI后不断重启的解决方法

    问题描述:用U盘启动进PE装的Win7,由于PE认不出硬盘,只好进BIOS设置硬盘模式为IDE才安装上.结果安装完系统后,在BIOS中强行修改硬盘模式为ACHI模式后,Win7开机不断重启,进不了系统 ...