Skip to content

Instantly share code, notes, and snippets.

@yanjinbin
Last active November 29, 2017 03:58
Show Gist options
  • Save yanjinbin/218e7de4b26956dfd343fac85ec56663 to your computer and use it in GitHub Desktop.
Save yanjinbin/218e7de4b26956dfd343fac85ec56663 to your computer and use it in GitHub Desktop.
break陷阱
func foo_while() {
sum := 0
for {
// todo 为什么不是100而是101
//sum++
//fmt.Printf("sum的值是%v\n",sum)
fmt.Printf("比较前的值%v\n",sum)
if sum > 100 {
fmt.Printf("\n sum>100 %v\n",sum)
break
}
fmt.Printf("sum++前的值\t%v\n",sum)
sum++
fmt.Printf("sum++后的值是%v\n",sum)
}
fmt.Printf("\nsum的值应该是100 是吗? %v\n", sum)
}
@yanjinbin
Copy link
Author

所以并不是个break trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment