当前位置:网站首页>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
}
}
}
边栏推荐
- awk从入门到入土(18)gawk线上手册
- Some points needing attention in PMP learning
- UML sequence diagram [easy to understand]
- China electronic grade sulfur trioxide Market Forecast and investment strategy report (2022 Edition)
- How to batch change file extensions in win10
- 2022-2028 research and trend analysis report on the global edible essence industry
- How to write unit test cases
- Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
- Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
- awk从入门到入土(6)正则匹配
猜你喜欢

After unplugging the network cable, does the original TCP connection still exist?

Implementation principle of redis string and sorted set

awk从入门到入土(12)awk也可以写脚本,替代shell

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

Ehrlich sieve + Euler sieve + interval sieve

How to ensure the uniqueness of ID in distributed environment
![Reload CUDA and cudnn (for tensorflow and pytorch) [personal sorting summary]](/img/3f/a71b56a62d2a0d64749a6af05384f5.jpg)
Reload CUDA and cudnn (for tensorflow and pytorch) [personal sorting summary]

At the age of 30, I changed to Hongmeng with a high salary because I did these three things

2022-2028 global visual quality analyzer industry research and trend analysis report

到底什么才是DaaS数据即服务?别再被其他DaaS概念给误导了
随机推荐
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
LinkedList in the list set is stored in order
C语言-入门-基础-语法-[变量,常亮,作用域](五)
Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
Basic discipline formula and unit conversion
"How to connect the network" reading notes - Web server request and response (4)
What is permission? What is a role? What are users?
awk从入门到入土(11)awk getline函数详解
Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
"How to connect the Internet" reading notes - FTTH
Jianzhi offer 09 realizes queue with two stacks
Codeforces Round #803 (Div. 2)(A-D)
If you can quickly generate a dictionary from two lists
Reading notes of how the network is connected - understanding the basic concepts of the network (I)
随机事件的关系与运算
awk从入门到入土(7)条件语句
Launpad | basic knowledge
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
Flutter tips: various fancy nesting of listview and pageview
Mac platform forgets the root password of MySQL