for [condition | ( init; condition; increment ) | Range]
{
statement(s);
}
package main
import "fmt"
func main() {
var b int = 15
var a int
numbers := [6]int{1, 2, 3, 5}
/* for loop execution */
for a := 0; a 10; a++ {
fmt.Printf("value of a: %d\n", a)
}
for a b {
a++
fmt.Printf("value of a: %d\n", a)
}
for i,x:= range numbers {
fmt.Printf("value of x = %d at %d\n", x,i)
}
}
for [condition | ( init; condition; increment ) | Range]
{
for [condition | ( init; condition; increment ) | Range]
{
statement(s);
}
statement(s);
}
package main
import "fmt"
func main() {
/* local variable definition */
var i, j int
for i=2; i 100; i++ {
for j=2; j = (i/j); j++ {
if(i%j==0) {
break; // if factor found, not prime
}
}
if(j > (i/j)) {
fmt.Printf("%d is prime\n", i);
}
}
}