Switch Statement in Go
Golang like most other programming languages has switch statement. Here is how to use switch statement in Golang.
Hello, World! is the first basic program in any programming language. You can write this first program in Golang by following the steps below.
First, open the Go compiler. In the Go language, programs are saved with the .go extension and are UTF-8 text files.
Now, first add the main package to your program:
package main
Every program must start with a package declaration . In Go, packages are used to organize and reuse code. In Go , there are two types of programs available, executables and libraries. Executables are programs that can be run directly from the terminal. Libraries are program packages that we can reuse in our programs. Here, the main package tells the compiler that the package should be compiled into an executable program, not a shared library. This is the starting point of the program and also contains the main function .
After adding main package import “fmt” package to your program:
import(
"fmt"
)
Here, import keyword is used to import packages into the program and fmt package is used to implement formatted Input/Output using functions.
Now write code in main function to print hello world in Go language:
func main() {
fmt.Println("!... Hello World ...!")
}
In the above lines of code, we have:
For example:
// Chương trình Go đầu tiên
package main
import "fmt";
// Hàm chính
func main() {
fmt.Println("!... Hello World ...!")
}
Result:
!... Hello World ...!
How to run Golang program
To run a Go program, you need a Go compiler. Once you have a Go compiler, first create a program and save your program with the .go extension , for example, first.go . Now we run this first.go file in the go compiler using the following command, i.e.:
$ go run first.go
Golang like most other programming languages has switch statement. Here is how to use switch statement in Golang.
In this article, we will learn how to use default case to avoid deadlock. But first, we will learn what is deadlock case when using select command in Golang?
Anonymous structs in Golang are temporary structures with no names used for one-time purposes, while anonymous fields allow embedding of unnamed fields.
What is Rune in Golang? How to use Rune in Golang? This article will give you the answer.
Operators allow us to perform different types of operations on operands. In Go language, operators can be classified based on their different functions.
_(underscore) in Golang is called Blank Identifier. Identifier is a user-defined name of program elements used for identification purposes.
Golang can be easily installed on Windows. Here is a step-by-step guide to install Golang on Windows.
Golang allows creating two or more methods with the same name in the same package, but the receivers of these methods must be of different types.
In Go, functions are blocks of code that perform specific tasks, which can be reused throughout the program to save memory, improve readability, and save time.
The scope of a variable in Golang determines which part of the program the variable is accessible to. In Go, all identifiers have a lexical scope that is determined at compile time.
What conditional statements does Golang have? How to use conditional statements in Go programming? Let's find out together!
The short variable declaration operator (:=) in Golang is used to create variables with a proper name and initial value. Here is what you need to know about the short variable declaration operator in Golang.
In Go, defer statements delay execution of a function or method or an anonymous method until the nearby functions return.
Methods in Golang are like functions but with one major difference: they have a receiver argument, which allows access to the properties of the receiver.
How many kilometers are 120 light years? How many kilometers are 40 light years? Let's find out together about a light year to find the answer!
The timing of your Instagram Reels can make the difference between massive engagement and dead silence. Let’s find out the best times to post on Instagram Reels.
There are many funny captions about dogs on the Internet. This article will gather for you the funniest, most humorous, and most interesting poems about dogs.
You will have the best gaming experience if you use Open NAT or at least Moderate NAT. That is why you need to learn how to change the NAT type.
After several updates, Apple Notes still lacks some features that could make the app even better.
You probably know that password managers are great for storing your online logins. But did you know they have many other great uses?
With the Messenger heart icon, you can choose different colors to use for different situations to express what you want to say to the other person.
Not only can you use Meta AI with individual WhatsApp messages, you can now send Meta AI messages in WhatsApp groups.
The concept of artificial intelligence - AI is becoming more and more popular, which means that this superior technology is gradually being effectively deployed in many fields as well as in all aspects of modern life.
Researchers at Penn Engineering (USA) are said to have discovered previously unidentified security vulnerabilities in a number of AI-controlled robotic platforms.
If you look at your wireless router, you may see the abbreviations LAN and WAN, usually located next to some ports on the device. LAN stands for Local Area Network and WAN stands for Wide Area Network. So what is the difference between these two types of ports? Let's find out with Quantrimang through the following article!
Smartphones are great for editing photos, but you should consider using a computer instead. There's a reason the pros do things differently.
Thanks to FilePizza, you can finally share large files without the need for a middleman.
The 20 longest flights in the world by distance (all longer than 12,000km and with flight times ranging from 15 hours 5 minutes to 18 hours 50 minutes).
The world's first Jet Suit Race was held in Dubai by Gravity Industries, a pioneer in jet suits, in partnership with the Dubai Sports Council.