25 Basic Keywords Of The Go Programming Language (Learn 'Go' - Part 2)
The 'Go' programming language is considered simple to learn as compared to other programming languages like C++. C++ has more than 70 basic keywords, whereas 'Go' has 25 keywords. It has been designed to be easy and simple to implement while being efficient. It allows the developers to develop at a good speed but the number of keywords is not the only factor that determines the complexity of the language.
Here is the list of 25 reserved 'Go' keywords that you will be using all the time. It is good to get familiar with all of them even before you start developing any software using 'Go.' Remember, these are the reserved keywords and you cannot use them as identifiers.
break - The 'break' keyword lets you terminate a loop and continue execution of the rest of the code.
case - This is a form of a 'switch' construct. We specify a variable after the switch.
chan - The 'chan' keyword is used to define a channel. In 'Go', you are allowed to run parallel pieces of code simultaneously.
const - The 'const' keyword is used to introduce a name for a scalar value like 2 or 3.14, etc.
continue - The 'continue' keyword allows you to go back to the beginning of the 'for' loop.
default - The 'default' statement is optional but you need to use either case or default within the switch statement. The switch jumps to the default value if the case does not match the controlling expression.
defer - The 'defer' keyword is used to defer the execution of a function until the surrounding function executes.
else - The 'else' keyword is used with the 'if' keyword to execute an alternate statement if a certain condition is false.
fallthrough - This keyword is used in a case within a switch statement. When we use this keyword, the next case is entered.
for - The 'for' keyword is used to begin a for loop.
func - The 'func' keyword is used to declare a function.
go - The 'go' keyword triggers a goroutine which is managed by the golang-runtime.
goto - The 'goto' keyword offers a jump to a labeled statement without any condition.
if - The 'if' statement is used to check a certain condition within a loop.
import - The 'import' keyword is used to import packages.
interface - The 'interface' keyword is used to specify a method set. A method set is a list of methods for a type.
map - The 'map' keyword defines a map type. A map os an unordered collection of the key-value pairs.
package - The code is grouped as a unit in a package. The 'package' keyword is used to define one.
range - The 'range' keyword lets you iterate items over the list items like a map or an array.
return - Go allows you to use the return values as variables and you can use the 'return' keyword for that purpose.
select - The 'select' keyword lets a goroutine to wait during the simultaneous communication operations.
struct - Struct is a collection of fields. We can use the 'struct' keyword followed by the field declarations.
switch - The 'switch' statement is used to start a loop and use the if-else logic within the block.
type - We can use the 'type' keyword to introduce a new struct type.
var - The 'var' keyword is used to create the variables in the 'Go' language.
If you are familiar with programming, you can make sense out of it instantly but if Go is your first programming language, you might not be able to make too much sense.
Don't worry! I have created this list only to make you familiar with the language. I will be covering all of them and other syntax elements in great detail in the upcoming posts. The learning has not even begun yet.
Thank You!
In Part 1, you got an Introduction To 'Go' Programming Language
In Part 3, you will learn 'How To Set The Go Programming Environment On Your System?'
In Part 4, you will 'Create Your First Program In Go language.'