Please enter each input on a new line. Use the textarea below to provide your input.
Go, also known as Golang, is an open-source programming language developed by Google. It is designed for simplicity and efficiency, making it ideal for developing scalable and high-performance applications. Learn more at Go Official Site.
Here’s a simple example of Go code:
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
This example demonstrates Go's package structure and how to print a message to the console.
Here are several beginner-friendly examples of Go code:
package main
import "fmt"
func main() {
var name string = "Go"
var age int = 11
var height float64 = 1.80
var isFun bool = true
fmt.Println("Name:", name, "Age:", age, "Height:", height, "Is Fun:", isFun)
}
This example illustrates the declaration of different data types in Go. Learn more
Conditional statements help control the flow of the program:
package main
import "fmt"
func checkAge(age int) {
if age >= 18 {
fmt.Println("You are an adult.")
} else {
fmt.Println("You are a minor.")
}
}
func main() {
checkAge(20) // Output: You are an adult.
}
This example shows how to use an if-else statement to check the age. Learn more
Go supports different types of loops:
package main
import "fmt"
func main() {
for i := 1; i <= 5; i++ {
fmt.Println("Count:", i)
}
count := 5
for count > 0 {
fmt.Println("Countdown:", count)
count--
}
}
This example demonstrates a for loop and a while-like loop in Go. Learn more
Functions in Go can be defined using the func
keyword:
package main
import "fmt"
func add(a int, b int) int {
return a + b
}
func main() {
fmt.Println("Sum:", add(3, 4)) // Output: Sum: 7
}
This example illustrates how to define and call a simple function in Go. Learn more
Here's a basic example of defining a struct and creating a method:
package main
import "fmt"
type Car struct {
model string
year int
}
func (c Car) display() {
fmt.Println("Model:", c.model, "Year:", c.year)
}
func main() {
myCar := Car{"Toyota", 2020}
myCar.display() // Output: Model: Toyota Year: 2020
}
This example demonstrates how to define a struct and a method in Go. Learn more