DEV Community

Ammar-Baig19
Ammar-Baig19

Posted on

Go Lang Introduction

Introduction to Go Lang:
The open-source programming language Go Lang was developed by Google in 2007. It is a statically-composed, ordered language that is intended to be capable, clear, and easy to remember. Go Lang is well-known for its lightning-fast execution speed, integrated concurrency capabilities, and strong emphasis on simplicity.

Setting up the Environment:
Before we can start writing Go programs, we need to set up our environment. We can download the Go Lang compiler and tools from the official website (https://golang.org/). Once we have downloaded and installed Go, we can create a new file with the extension ".go" and write our first Go program.

Syntax:

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
Enter fullscreen mode Exit fullscreen mode

Data Types used in GO:
Commonly used data types in Go Lang are:
Integer types: int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr.
Floating-point types: float32, float64.
Complex types: complex64, complex128.
Boolean type: bool.
String type: string.
Array type: [n]T, where n is the number of elements and T is the element type.
Slice type: []T, where T is the element type.
Map type: map[K]V, where K is the key type and V is the value type.
Pointer type: T, where T is the type of the pointed-to value.
**Struct type:
* struct{}.
Interface type: interface{}.
Function type: func(). These are just a few examples of commonly used data types in Go Lang. Go Lang also provides additional types such as byte, rune, error, channel, and time.

Control Structures:
Go Lang provides several control structures that are used to manage the flow of execution in a program. Here are some commonly used control structures in Go Lang:
if/else statements: Used to execute code based on a condition. The if statement executes a block of code if a condition is true. The else statement executes a block of code if the condition is false.
switch statements: Used to evaluate a variable or expression against a list of possible values. The switch statement executes the block of code that matches the value of the variable or expression.
for loops: Used to execute a block of code repeatedly. The for loop allows you to specify a condition to determine how many times the loop should execute.
break and continue statements: Used to control the flow of a loop. The break statement terminates the loop immediately, while the continue statement skips the current iteration of the loop.
defer statements: Used to schedule a function call to be executed after the surrounding function returns. Defer statements are often used to perform cleanup tasks, such as closing files or releasing resources.
goto statements: Used to transfer control to a labeled statement elsewhere in the code. However, the use of goto statements is generally discouraged in Go Lang, and it is recommended to use other control structures instead.

Apache-Age
GitHub

Top comments (0)