- Write a loop to ask the name and age from a user and print "Your name is ___ and your age is ___ years old"
- This should be infinite loop
- Define the following array
"pizza"}
- Append to it the following item: "hamburger"
- Append to it the following item: "salad"
- Iterate over the list and print for each item
Food: <Food name>
. Make sure to replace <Food name>
with item from the array
- Define the following fixed array of 3 items:
{square, circle, triangle}
- Iterate over it and print for each item the following:
This is <ITEM> and its index in the array is <INDEX>
package main
import "fmt"
func main() {
var name string
var age uint
for {
fmt.Print("\nEnter your name: ")
fmt.Scan(&name)
fmt.Print("Enter your age: ")
fmt.Scan(&age)
fmt.Printf("\nYour name is %v and your age is %v years old\n", name, age)
}
}
package main
import "fmt"
func main() {
var foods = []string{"pizza"}
foods = append(foods, "hamburger")
foods = append(foods, "salad")
for _, food := range foods {
fmt.Printf("Food: %v\n", food)
}
}
- .
package main
import "fmt"
func main() {
var shapes = [3]string{"square", "circle", "triangle"}
for index, shape := range shapes {
fmt.Printf("This is %v and its index in the array is %v\n", shape,index)
}
}