当前位置:网站首页>Explanation of for loop in golang
Explanation of for loop in golang
2022-07-04 09:16:00 【The diligent bird that flies first】
Special Usage 1:
Be similar to while Usage of
func main(){
i := 2
for i<4 {
fmt.Println("hello")
i++
}
}
for Dead cycle usage , Usually and break Use it together
That is to say for In circulation , First, judge the conditions of variables , And then in the follow-up work
func main(){
i := 0
for{
if i>=10{
break
}
fmt.Println(i)
i++
}
}
for range Realization
// Method four : Use for range Judge
// Use string as an example
func main(){
str := "hello Lu Changqi !"
for i:=0; i<len(str); i++{
// In case of garbled code
// h e l l oåéå
fmt.Printf("%c \n", str[i])
}
fmt.Println("---------------------------")
// The solution to garbled code :
// Method 1 : Turn into rune[]
rune_str := []rune(str)
for i:=0; i<len(rune_str); i++{
fmt.Printf("%c \n", rune_str[i])
}
// Method 2 : Use for range Traversal
for _, val := range str{
fmt.Printf("%c \n", val)
}
}
while and do while The implementation of the
// while and do while The implementation of the
// while The implementation of the
func main6(){
i := 0
for{
if i>=10{
break
}
fmt.Println(i)
i++
}
}
// do while The implementation of the
func main(){
i:=0
for {
fmt.Println(i)
i++
if i>=10{
break
}
}
}
边栏推荐
- LeetCode 74. Search 2D matrix
- In depth research and investment strategy report on China's hydraulic parts industry (2022 Edition)
- Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
- 2022-2028 global edible probiotic raw material industry research and trend analysis report
- Awk from digging into the ground to getting started (10) awk built-in functions
- Report on investment analysis and prospect trend prediction of China's MOCVD industry Ⓤ 2022 ~ 2028
- C语言-入门-基础-语法-[标识符,关键字,分号,空格,注释,输入和输出](三)
- Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022-2028 global strain gauge pressure sensor industry research and trend analysis report
- Launchpad x | mode
猜你喜欢
Codeforces Round #793 (Div. 2)(A-D)
HMS core helps baby bus show high-quality children's digital content to global developers
LeetCode 74. Search 2D matrix
Implementation principle of redis string and sorted set
Solve the problem of "Chinese garbled MySQL fields"
AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
ArrayBuffer
After unplugging the network cable, does the original TCP connection still exist?
C語言-入門-基礎-語法-[運算符,類型轉換](六)
C language - Introduction - Foundation - syntax - [operators, type conversion] (6)
随机推荐
2022-2028 global small batch batch batch furnace industry research and trend analysis report
Awk from entry to earth (12) awk can also write scripts to replace the shell
2022-2028 global tensile strain sensor industry research and trend analysis report
1211 or chicken and rabbit in the same cage
awk从入门到入土(4)用户自定义变量
Clion console output Chinese garbled code
Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
DR6018-CP01-wifi6-Qualcomm-IPQ6010-IPQ6018-FAMILY-2T2R-2.5G-ETH-port-CP01-802-11AX-MU-MIMO-OFDMA
到底什么才是DaaS数据即服务?别再被其他DaaS概念给误导了
Trees and graphs (traversal)
地平线 旭日X3 PI (一)首次开机细节
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
Simulate EF dbcontext with MOQ - mocking EF dbcontext with MOQ
Reading notes on how to connect the network - tcp/ip connection (II)
Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
Report on the development trend and prospect trend of high purity zinc antimonide market in the world and China Ⓕ 2022 ~ 2027
如何编写单元测试用例
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
《网络是怎么样连接的》读书笔记 - 认识网络基础概念(一)
awk从入门到入土(18)gawk线上手册