Last active
November 29, 2017 03:58
-
-
Save yanjinbin/218e7de4b26956dfd343fac85ec56663 to your computer and use it in GitHub Desktop.
break陷阱
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
所以并不是个break trick