// for
sum := 0
for i := 0; i <= 100; i++ {
sum += i
}
// 转二进制
fun convertToBin(n int) string {
result := ""
for ; n > 0; n /= 2 {
lsb := n % 2
result = strconv.Itoa(lsb) + result
}
return result
}
//
fun printFile(fileName string) {
file, err := os.Open(fileName)
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(file)
// 相当于 while, go 没有 while
for scanner.Scan() {
fmt.PrintIn(scanner.Text())
}
}
// 死循环
func forever() {
for {
fmt.PrintIn("xxx")
}
}
09-06
621
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)