10 examples of 'golang infinite loop' in Go

Every line of 'golang infinite loop' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
128func LoopIndirect(vValue reflect.Value) reflect.Value {
129 for vValue.Kind() == reflect.Ptr {
130 vValue = vValue.Elem()
131 }
132 return vValue
133}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

23func main() {
24 starttime := time.Now()
25
26 total := 0
27 for i := int64(0); i < 100000000; i++ {
28 if isOdd(i+euler.IntReverse(i)) && i%10 != 0 {
29 total++
30 }
31
32 }
33
34 fmt.Println(total)
35
36 fmt.Println("Elapsed time:", time.Since(starttime))
37
38}
856func (_this *HTMLMediaElement) Loop() bool {
857 var ret bool
858 value := _this.Value_JS.Get("loop")
859 ret = (value).Bool()
860 return ret
861}
164func loop(ints ...int64) (<-chan int64, error) {
165 var start, stop int64
166 switch len(ints) {
167 case 1:
168 start, stop = 0, ints[0]
169 case 2:
170 start, stop = ints[0], ints[1]
171 default:
172 return nil, fmt.Errorf("loop: wrong number of arguments, expected 1 or 2"+
173 ", but got %d", len(ints))
174 }
175
176 ch := make(chan int64)
177
178 go func() {
179 for i := start; i < stop; i++ {
180 ch <- i
181 }
182 close(ch)
183 }()
184
185 return ch, nil
186}
78func (c *Client) loop() {
79 for {
80 select {
81 case call := <-c.updates:
82 call()
83 default:
84 if C.pa_mainloop_iterate(c.mainloop, 1, nil) < 0 {
85 fmt.Println("Exiting PulseAudio loop")
86 return
87 }
88 }
89 }
90}
214func (o Opcodes) Loop(ops ...Operand) { o.a.op("LOOP", ops...) }
368func (list *List) LoopTypeDetect() int {
369 slowPtr := list.head
370 fastPtr := list.head
371 for fastPtr.next != nil && fastPtr.next.next != nil {
372 if list.head == fastPtr.next || list.head == fastPtr.next.next {
373 fmt.Println("circular list loop found")
374 return 2
375 }
376 slowPtr = slowPtr.next
377 fastPtr = fastPtr.next.next
378 if slowPtr == fastPtr {
379 fmt.Println("loop found")
380 return 1
381 }
382 }
383 fmt.Println("loop not found")
384 return 0
385}
27func loop() bool {
28 fmt.Print("Monkey>>")
29 command := ""
30
31 i := 0
32 for !strings.Contains(command, ";") {
33 if i > 0 {
34 fmt.Print(" ->")
35 }
36 cmd, _ := inReader.ReadString('\n')
37 command += cmd
38 i++
39 }
40 if strings.Contains(command, "quit;") {
41 return false
42 }
43
44 ts, _ := lex.Parse(*lex.NewByteReader([]byte(command)))
45 if *lexSwitch {
46 fmt.Println(command)
47 fmt.Println(ts)
48 }
49 stn, err := syntax.Parser(syntax.NewTokenReader(ts))
50 if err != nil {
51 fmt.Fprintln(os.Stderr, err.Error())
52 return true
53 }
54 if *syntaxSwitch {
55 stn.Print(1)
56 }
57 r, re, err := plan.DirectPlan(stn)
58 if err != nil {
59 fmt.Fprintln(os.Stderr, err.Error())
60 return true
61 }
62 r.Print()
63 fmt.Println(re.AffectedRows, " row(s) affected in ", (float64)(re.UsedTime)/1000000000, "s.")
64 return true
65}
119func testSlicePanic2() {
120 defer func() {
121 if r := recover(); r != nil {
122 println("panicked as expected")
123 }
124 }()
125
126 a := [10]int{0, 10, 20, 30, 40, 50, 60, 70, 80, 90}
127 testSliceGetElement_ssa(a, 3, 7, 4)
128 println("expected to panic, but didn't")
129 failed = true
130}
472func (p *Proc) NoLoop() {
473 p.ctl.mu.Lock()
474 defer p.ctl.mu.Unlock()
475 p.ctl.loop = false
476}

Related snippets