In this article we will learn about some of the frequently asked GO programming questions in technical like “go for loop” Code Answer’s. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on go was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in GO. Below are some solution about “go for loop” Code Answer’s.
go for loop
xxxxxxxxxx
1
package main
2
3
import "fmt"
4
5
func main() {
6
sum := 0
7
for i := 0; i < 10; i++ {
8
sum += i
9
}
10
fmt.Println(sum)
11
}
golang loop
xxxxxxxxxx
1
package main
2
3
import "fmt"
4
5
func main() {
6
sum := 0
7
for i := 0; i < 10; i++ {
8
sum += i
9
}
10
fmt.Println(sum)
11
}
12
go for loop
xxxxxxxxxx
1
sum := 0
2
for i := 1; i < 5; i++ {
3
sum += i
4
}
5
fmt.Println(sum) // 10 (1+2+3+4)
go loops
xxxxxxxxxx
1
// There's only `for`, no `while`, no `until`
2
for i := 1; i < 10; i++ {
3
}
4
for ; i < 10; { // while - loop
5
}
6
for i < 10 { // you can omit semicolons if there is only a condition
7
}
8
for { // you can omit the condition ~ while (true)
9
}
10
11
// use break/continue on current loop
12
// use break/continue with label on outer loop
13
here:
14
for i := 0; i < 2; i++ {
15
for j := i + 1; j < 3; j++ {
16
if i == 0 {
17
continue here
18
}
19
fmt.Println(j)
20
if j == 2 {
21
break
22
}
23
}
24
}
25
26
there:
27
for i := 0; i < 2; i++ {
28
for j := i + 1; j < 3; j++ {
29
if j == 1 {
30
continue
31
}
32
fmt.Println(j)
33
if j == 2 {
34
break there
35
}
36
}
37
}
golang for
xxxxxxxxxx
1
for i, s := range arr {
2
}
3
for k,v := range map{
4
}
5
for{
6
break
7
}