Answers for "for loop iterate golang"

Go
-1

golang for loop

import (
  "fmt"
)

func main() {

  numbs := []int{1, 2, 3, 4, 5}

  for numb := range numbs {
     fmt.Printf("using range: %d \n", numb)
  }
  
  fmt.Println("\n")
    
  for i := 0; i < len(numbs); i++ {
    fmt.Printf("using for: %d \n", i)
  }
  
  fmt.Println("\n")

  i := 0
  for i < len(numbs) {
   fmt.Printf("using for like while: %d \n", i)
   i++
 }  
 
}
Posted by: Guest on March-30-2022

Browse Popular Code Answers by Language