Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30779
  • 博文数量: 11
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-19 21:19
文章分类
文章存档

2015年(2)

2014年(9)

我的朋友

分类: 敏捷开发

2014-11-24 21:23:11


点击(此处)折叠或打开

  1. // Switch
  2. package main

  3. import (
  4.     "fmt"
  5.     "time"
  6. )

  7. func main() {
  8.     //Here’s a basic switch.
  9.     i := 2
  10.     fmt.Print("write ", i, " as ")
  11.     switch i {
  12.     case 1:
  13.         fmt.Println("one")
  14.     case 2:
  15.         fmt.Println("two")
  16.     case 3:
  17.         fmt.Println("three")
  18.     }
  19.     //You can use commas to separate multiple expressions in the same case statement.
  20.     //We use the optional default case in this example as well.
  21.     switch time.Now().Weekday() {
  22.     case time.Saturday, time.Sunday:
  23.         fmt.Println("it's the weekend")
  24.     default:
  25.         fmt.Println("it's a weekday")
  26.     }
  27.     //switch without an expression is an alternate way to express if/else logic.
  28.     //Here we also show how the case expressions can be non-constants.
  29.     t := time.Now()
  30.     switch {
  31.     case t.Hour() < 12:
  32.         fmt.Println("it's before noon")
  33.     default:
  34.         fmt.Println("it's after noon")
  35.     }
  36. }
转自
阅读(1180) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~