Consider the following code which just prints all the ENV vars
package main
import (
"fmt"
"os"
)
func main() {
for i, env := range os.Environ() {
fmt.Println(i, env)
}
}
Here, os.Environ() is supposed to return array of strings([] string), to loop over it. I need to to use range keyword & also for loop. Question is:
- Why are both for & range required? is it possible to use for loop for this as
[]string
is already an array & we can iterate over arrays right? - In the above code what does
range
do? and what doesfor
loop does?
Sorry if this question is too stupid, I am just starting with Go