//iota -- similar to enum
package main import ( "fmt" ) const( _ = iota //_ means dummy variable which will be ignored. TrafficLightStateRedLight TrafficLightStateGreenLight TrafficLightStateYellowLight ) func main(){ fmt.Println("Red Light Status Code: ",TrafficLightStateRedLight) fmt.Println("Green Light Status Code: ",TrafficLightStateGreenLight) fmt.Println("Yellow Light Status Code: ",TrafficLightStateYellowLight) }
package main import ( "fmt" ) func main(){ const( LosAngeles = 1984+(iota * 4) Seoul Barcelona Atlanta Sydney Athens Beijing London Rio Tokyo ) fmt.Println("These cities hosted or will host the Summer Olympics in the provided year...") fmt.Printf("%-18s %-18s \n","City","Year") fmt.Printf("%-18s %-18v \n","Los Angeles",LosAngeles) fmt.Printf("%-18s %-18v \n","Atlanta",Atlanta) fmt.Printf("%-18s %-18v \n","Tokyo",Tokyo) fmt.Printf("%-18s %-18v \n","London",London) }
No comments:
Post a Comment