{}const=>[]async()letfn</>var
DevelopmentBasicsOverview

Go for beginners: A simple start in programming

Go is a fast, efficient, and easy-to-learn programming language. In this article, we will introduce you to the basics of Go, tell you how to write and run simple programs, and give clear examples. Start using Go today!

К

Kodik

Author

6 min read

What is Go? 🏃‍♂️💨

Go (or Golang) is a programming language developed by Google in 2007 and released in 2009. It is designed to be fast, simple and efficient. Go is ideal for creating high-performance applications, especially when it comes to multitasking (when the program performs several operations at the same time).

The main goal of Go is to simplify the development of complex applications, as well as increase their speed. In this article, we will introduce you to the basics of Go, its capabilities and create a few simple projects so that you can start programming right now! 🚀

How to start working with Go? 💻

To start working with Go, you need to install an interpreter. This is a special program that will run your Go programs. You can download Go from the official website golang.org. After installing Go, you will be able to write and run your programs via the command line.

Now that Go is installed, let's figure out how to write and run programs. But before we write the code, let's find out what we can do with Go!

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

Key features of Go 🔧

Go is a versatile language that provides ample opportunities for development. Here's what you can do with Go:

  • High performance: Go is compiled into machine code, which makes it as fast as C, but much easier to use. ⚡

  • Multitasking: Go makes it easy to work with multitasking (goroutines), allowing you to create highly efficient applications for processing multiple requests at the same time. 🧠

  • Syntax simplicity: Go has a minimalist syntax that is easy for beginners to learn. There are not many complex concepts here, as in other languages, which makes Go an excellent choice to start with. 📘

  • Tools for working with networks: Go includes powerful tools for working with web servers and clients, creating REST APIs, and interacting with various protocols. 🌐

  • Support for parallel computing: Go is great for developing multitasking applications, for example, for servers or distributed systems. ⏳

  • Built-in packages: Go provides many standard libraries for working with files, networks, databases, and regular expressions. 📦

Go Syntax Basics 📚

Go is a simple language with concise syntax. It allows you to quickly understand the structure of the program. Let's get to the basics.

1. Variables 📦

Variables in Go are places where information is stored. For example, you can create a variable to store a name, age, or number. In Go, variables are defined using the var keyword, and you can specify the data type (for example, int for integers or string for strings).

Example of a variable:

var name = "Alice"

Here the variable name stores the string "Alice". We do not specify the type of the variable, and Go will select the desired type itself.

Example with type:

var age int = 25

Here, the variable age has the type int (integer) and stores the value 25.

2. Functions 🛠️

Functions are blocks of code that perform a single task. In Go, functions are defined using the func keyword, and they can take arguments and return values.

Example of a function:

func greet() {
    fmt.Println("Hello, World!")
}

In this example, the greet function displays "Hello, World!" on the screen. To call this function, you just need to write its name:

greet()

3. Conditional operators (if... else) 🧐

If you need the program to make decisions, you can use conditional operators. For example, the program can check a person's age and display whether they are an adult or a child.

Example:

var age = 20
if age >= 18 {
    fmt.Println("You're an adult!")
} else {
    fmt.Println("You're still a child.")
}

4. Cycles 🔄

Loops allow you to repeat the same action several times. For example, you can print all numbers from 1 to 5 using a loop.

Example of the for cycle:

for i := 1; i <= 5; i++ {
    fmt.Println(i)
}

This loop will output numbers from 1 to 5. Why write the same thing 5 times if you can use a loop? 😄

5. Arrays and slices 🍽️

Arrays and slices are data collections. Arrays have a fixed length, and slices can change their size during program execution. Arrays are useful when the number of elements is known in advance, and slices are useful when it can change.

Array example:

var colors = [3]string{"red", "green", "blue"}

The colors array stores 3 strings. You can access the elements of the array by index (starting from 0):

fmt.Println(colors[0])  // Will output: red

Simple projects on Go 💡

1. Multiplication and division calculator ➗

Let's create a program that will multiply two numbers and divide one by the other. This is a simple program that will help you understand how to work with numbers and operations in Go.

package main
import "fmt"

func main() {
    var a, b float64
    a = 10
    b = 2

    multiplication := a * b
    division := a / b

    fmt.Println("Multiplication: ", multiplication)
    fmt.Println("Division: ", division)
}

This calculator will first multiply two numbers, then divide them and display the results. All numbers here are set in advance.

2. Prime number (prime test) 🔢

Now let's create a program that will check whether a number is prime. A prime number is a number that is divisible only by 1 and itself.

package main
import "fmt"

func isPrime(n int) bool {
    if n <= 1 {
        return false
    }
    for i := 2; i*i <= n; i++ {
        if n%i == 0 {
            return false
        }
    }
    return true
}

func main() {
    number := 29
    if isPrime(number) {
        fmt.Println(number, "it's a prime number")
    } else {
        fmt.Println(number, "this is not a simple number")
    }
}

This script will check if the number is prime. We check the number 29 — it is a prime number, and the program will display the corresponding message.

3. The sum of all elements of the array 📊

Let's write a program that will sum up all the elements of the array. This is a useful task for working with data collections, for example, for calculating totals.

package main
import "fmt"

func main() {
    numbers := [5]int{1, 2, 3, 4, 5}
    var sum int

    for _, number := range numbers {
        sum += number
    }

    fmt.Println("Sum of all numbers:", sum)
}

This program creates an array of numbers and sums them up. We use a loop to go through each number and add it to the total.

Conclusion 🎉

Now you have learned the basics of Go and created a few simple programs. Go is a fast, efficient, and easy-to-learn language that is ideal for building server applications, data processing, and multitasking.

Remember that the best way to learn how to program is to practice. The more you work with Go, the faster you will become a confident developer. Good luck in mastering Go! 🚀

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card