Lets dig straight to the topic.
For loops can be formed in below way which is straightforward like any other language
package main
import "fmt"
func main()
for startvalue:=0;startvalue<10;startvalue++
fmt.Print( startvalue)
and when iterating over array in for loop we get two return values. the index and the actual value.
package main
import "fmt"
func main()
nums:=[]int641,2,3,4,5,6,7,8,9,10,11
for i, num := range nums // i is the index and num is the value from the array , if we are not bothered about the index then we can give like for _, num := range nums
fmt.Println("index:", i,num)
Comments
Post a Comment