Difference between revisions of "Loop"

From wikieduonline
Jump to navigation Jump to search
Line 6: Line 6:
 
[[go]]
 
[[go]]
 
<pre>
 
<pre>
sum := 0
+
package main
for {
+
import "fmt"
     sum++ // repeated forever
+
 
 +
func main() {
 +
  sum := 0
 +
  for {
 +
     sum++  
 
     fmt.Println(sum)
 
     fmt.Println(sum)
 +
  }
 
}
 
}
 
</pre>
 
</pre>

Revision as of 08:12, 29 April 2020


Infinite loop

go

package main
import "fmt"

func main() {
  sum := 0
  for {
    sum++ 
    fmt.Println(sum)
  }
}

Go do not support parallel for-loops , deprecated Sun's Fortress was support it. But they are easy to implement using goroutines.[1]


Bash

#!/bin/bash
while true; do
 ((var++))
echo $var
done


Related terms


See also

  • http://www.golangpatterns.info/concurrency/parallel-for-loop
  • Advertising: