Next: , Previous: , Up: Exercises   [Index]


1.2.4.2 Exercise 1.2

Modify the echo program to print the index and value of each of its arguments, one per line.

// Echo the command-line arguments, and print the index and value of each argument
// on a separate line
package main

import (
        "fmt"
        "os"
)

func main() {
        for index, value := range os.Args[0:] {
                fmt.Println(index, value)
        }
}

Listing 1.12: Ch1 Exercise 1.2