当前位置:网站首页>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
}
}
}
边栏推荐
- If you can quickly generate a dictionary from two lists
- [untitled] forwarding least square method
- 2022-2028 global special starch industry research and trend analysis report
- Awk from entry to earth (12) awk can also write scripts to replace the shell
- Report on research and investment prospect prediction of China's electronic grade sulfuric acid industry (2022 Edition)
- 2022-2028 global seeder industry research and trend analysis report
- Flutter tips: various fancy nesting of listview and pageview
- Launchpad x | mode
- Awk from entry to earth (15) awk executes external commands
- Solve the problem of "Chinese garbled MySQL fields"
猜你喜欢
![[error record] no matching function for call to 'cacheflush' cacheflush();)](/img/79/c00f9c835606b2dce1d342ec368d24.jpg)
[error record] no matching function for call to 'cacheflush' cacheflush();)

Relationship and operation of random events

2022-2028 global edible probiotic raw material industry research and trend analysis report

Opencv environment construction (I)

MySQL foundation 02 - installing MySQL in non docker version

How should PMP learning ideas be realized?

2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report

2022-2028 global strain gauge pressure sensor industry research and trend analysis report
](/img/5a/c6a3c5cd8038d17c5b0ead2ad52764.png)
C语言-入门-基础-语法-[主函数,头文件](二)

26. Delete duplicates in the ordered array (fast and slow pointer de duplication)
随机推荐
Simulate EF dbcontext with MOQ - mocking EF dbcontext with MOQ
C language - Introduction - Foundation - syntax - [main function, header file] (II)
Explain TCP protocol in detail three handshakes and four waves
Basic discipline formula and unit conversion
随机事件的关系与运算
2022-2028 global optical transparency industry research and trend analysis report
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
awk从入门到入土(6)正则匹配
Research Report on research and investment prospects of China's testing machine industry (2022 Edition)
如何编写单元测试用例
In depth investigation and Strategic Research Report on China's motion controller Market (2022 Edition)
Dynamic analysis and development prospect prediction report of high purity manganese dioxide in the world and China Ⓡ 2022 ~ 2027
The old-fashioned synchronized lock optimization will make it clear to you at once!
C language - Introduction - Foundation - syntax - data type (4)
awk从入门到入土(8)数组
awk从入门到入土(11)awk getline函数详解
Reload CUDA and cudnn (for tensorflow and pytorch) [personal sorting summary]
Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027