Keywords in Go

Golang is a programming language that has gained significant popularity in recent years due to its simplicity and readability of syntax, supported by the use of keywords.

Keyword - Keywords or reserved words are words in the language that are used for some internal processes or represent some predefined actions. Therefore, these words are not allowed to be used as identifiers. Doing so will result in compilation errors. Here is what you need to know about keywords in Golang .

Keywords in Go

For example:

// Minh họa chương trình Go sử dụng từ khóa
package main 
import "fmt"

// Từ khóa ở đây là package, import, func, var 
func main() { 

// Đây là một biến hợp lệ
var a = "Quantrimang"

fmt.Println(a) 

// Ở đây, mặc định là một
// định danh không hợp lệ và
// trình biên dịch sẽ đưa ra lỗi
// var default = "GFG" 
} 

Result:

Quantrimang

Go programming currently has a total of 25 keywords:

Keywords in Go

  • break − Used to exit a loop or switch statement.
  • case − Used in a switch statement to specify a possible match for the input value.
  • chan − Used to create communication channels between goroutines.
  • const − Used to define a constant value that cannot be changed.
  • continue − Used to skip the current iteration of a loop and move to the next iteration.
  • defer − Used to schedule a function call to be executed after the current function returns.
  • else − Used to specify an alternative block of code to execute if the if condition is false.
  • fallthrough − Used in a switch statement to specify that control will pass to the next case.
  • for − Used to create a loop that repeats a block of code a specified number of times.
  • func − Used to define a function that can be called from other parts of the program.
  • go − Used to start a new goroutine.
  • goto − Used to jump to a specific label within the current function.
  • if − Used to execute a block of code only if a certain condition is true.
  • import − Used to import a package into the program.
  • interface − Used to define a set of methods that a type must implement.
  • map − Used to define a set of key-value pairs.
  • package − Used to define a package containing one or more Go source files.
  • range − Used to iterate over an array, slice, sequence, map, or channel.
  • return − Used to exit a function and return a value to the caller.
  • select − Used to wait for a value to be sent to one of multiple channels.
  • struct − Used to define a set of fields representing a complex data type.
  • switch − Used to execute a block of code based on the value of an expression.
  • type − Used to define a new data type.
  • var − Used to declare a variable.

For example:

// Minh họa chương trình Go sử dụng từ khóa

// Từ khóa package được dùng để bao gồm main package trong chương trình
package main 

// Từ khóa import được dùng để nhập "fmt" vào trong package 
import "fmt"

// func được dùng để tạo hàm
func main() { 

	// Từ khóa var được dùng để tạo biến
	// Pname, Lname, and Cname là các biến hợp lệ
	var Pname = "Quantrimang"
	var Lname = "Go Language"
	var Cname = "Keywords"
	
	fmt.Printf("Portal name: %s", Pname) 
	fmt.Printf("\nLanguage name: %s", Lname) 
	fmt.Printf("\nChapter name: %s", Cname) 

} 

Result:

Portal name: GeeksforGeeks
Language name: Go Language
Chapter name: Keywords

Whether you are a beginner or an experienced developer, mastering Golang keywords is an important step towards becoming a proficient Go programmer.

Leave a Comment

Causes of oil heater noise, oil leakage and no heating when in use

Causes of oil heater noise, oil leakage and no heating when in use

Oil heaters make noise, leak oil, and do not heat up. These are all problems that arise when using a heater. So what are the causes of these problems? Read our article below!

How to Assign Participants to Breakout Rooms in Microsoft Teams

How to Assign Participants to Breakout Rooms in Microsoft Teams

Master how to assign participants to breakout rooms in Microsoft Teams with this step-by-step guide. Boost meeting engagement, automate assignments, and troubleshoot like a pro for seamless virtual collaboration.

How to Fix Microsoft Teams Giá Error Pricing Update

How to Fix Microsoft Teams Giá Error Pricing Update

Struggling with Microsoft Teams "Price Error" after the latest pricing update? Discover step-by-step fixes to resolve it quickly, restore seamless collaboration, and avoid subscription headaches. Updated with the newest solutions.

Solving Microsoft Teams Background Error Transparency

Solving Microsoft Teams Background Error Transparency

Struggling with Microsoft Teams Background Error Transparency? Discover proven step-by-step fixes for blurry, glitchy virtual backgrounds. Restore perfect transparency in Teams meetings effortlessly. Updated with the latest solutions.

How to Fix Microsoft Teams Đăng nhập Error (Login)

How to Fix Microsoft Teams Đăng nhập Error (Login)

Struggling with Microsoft Teams "Đăng nhập" login error? Discover step-by-step fixes for smooth sign-in. Clear cache, update app, and more – no tech skills needed! Works on Windows, Mac, and web.

Solving Microsoft Teams Web Error 503 Service Unavailable

Solving Microsoft Teams Web Error 503 Service Unavailable

Tired of Microsoft Teams Web Error 503 Service Unavailable blocking your meetings? Discover quick, step-by-step fixes to resolve the 503 error fast – no tech skills needed! Clear cache, check status, and get back to collaborating seamlessly.

Troubleshooting Microsoft Teams Update Error 0x80070002

Troubleshooting Microsoft Teams Update Error 0x80070002

Stuck with Microsoft Teams Update Error 0x80070002? Discover proven troubleshooting steps to resolve this frustrating issue quickly and get your Teams app updated seamlessly for uninterrupted collaboration.

Solving Microsoft Teams Error AADSTS50020: User Account Conflict

Solving Microsoft Teams Error AADSTS50020: User Account Conflict

Tired of Microsoft Teams Error AADSTS50020 blocking your sign-in? Discover step-by-step fixes for user account conflicts, backed by the latest Azure AD solutions. Get back to work fast!

How to Fix Microsoft Teams Microphone Error No Sound

How to Fix Microsoft Teams Microphone Error No Sound

Tired of Microsoft Teams microphone error with no sound? Discover quick, step-by-step fixes for Teams mic not working on Windows, Mac, and more. Restore crystal-clear audio in minutes!

How to Fix Microsoft Teams Task Management Error

How to Fix Microsoft Teams Task Management Error

Tired of the Microsoft Teams "Task Management" Error disrupting your workflow? Discover proven fixes like clearing cache, updating Teams, and troubleshooting permissions to get back to seamless collaboration in minutes. Updated with the latest solutions.

How to Fix Microsoft Teams How to Teams Help Error

How to Fix Microsoft Teams How to Teams Help Error

Frustrated by the Microsoft Teams 'How to Teams' Help Error? Discover proven, step-by-step solutions to fix it quickly and restore smooth help access. Latest 2026 updates included for seamless teamwork.

Solving Microsoft Teams Room Error Syncing

Solving Microsoft Teams Room Error Syncing

Struggling with Microsoft Teams "Room Error" Syncing? This ultimate guide provides step-by-step fixes for Microsoft Teams Room Error Syncing issues, ensuring seamless meetings and quick resolutions. Updated with the latest tips.

Troubleshooting Microsoft Teams Workflows Power Automate

Troubleshooting Microsoft Teams Workflows Power Automate

Master troubleshooting Microsoft Teams Workflows Power Automate issues with step-by-step fixes for common errors. Get your automations running smoothly – no more frustration! Proven solutions for triggers, permissions, and more.

Solving Microsoft Teams Restart Error (2026)

Solving Microsoft Teams Restart Error (2026)

Struggling with Microsoft Teams "Restart Error" in 2026? Discover proven, step-by-step fixes to resolve the endless restart loop quickly. Clear cache, reset app, and more for seamless collaboration. Get back online fast!

How to Create Breakout Rooms in Microsoft Teams Before a Meeting

How to Create Breakout Rooms in Microsoft Teams Before a Meeting

Master how to create breakout rooms in Microsoft Teams before a meeting with this easy guide. Pre-assign participants, boost collaboration, and elevate your virtual sessions effortlessly.