Loading lesson path
Go
Go Tutorial focused on Go Introduction and related concepts.
Go is a popular programming language.
- Go is a cross-platform, open source programming language Go can be used to create high-performance applications Go is a fast, statically typed, compiled language known for its simplicity and effici…
To start using Go, you need two things:
A Go file consists of the following parts:
A comment is a text that is ignored upon execution.
Variables are containers for storing data values.
In Go, it is possible to declare multiple variables on the same line.
A variable can have a short name (like x and y) or a more descriptive name (age, price, carname, etc.).
If a variable should have a fixed value that cannot be changed, you can use the const keyword.
Go has three functions to output text:
Go offers several formatting verbs that can be used with the Printf() function.
Data type is an important concept in programming. Data type specifies the size and type of variable values.
A boolean data type is declared with the bool keyword and can only take the values true or false .
Integer data types are used to store a whole number without decimals, like 35, -50, or 1345000.
The float data types are used to store positive and negative numbers with a decimal point, like 35.3, -2.34, or 3597.34987.
The string data type is used to store a sequence of characters (text). String values must be surrounded by double quotes:
Arrays are used to store multiple values of the same type in a single variable, instead of declaring separate variables for each value.
Slices are similar to arrays, but are more powerful and flexible.
You can access a specific slice element by referring to the index number.
Operators are used to perform operations on variables and values.
Arithmetic operators are used to perform common mathematical operations.
Assignment operators are used to assign values to variables.
Comparison operators are used to compare two values.
Logical operators are used to determine the logic between variables or values:
Bitwise operators are used on (binary) numbers:
Conditional statements are used to perform different actions based on different conditions.
Use the if statement to specify a block of Go code to be executed if a condition is true .
Use the else statement to specify a block of code to be executed if the condition is false .
Use the else if statement to specify a new condition if the first condition is false .
You can have if statements inside if statements, this is called a nested if.
Use the switch statement to select one of many code blocks to be executed.
It is possible to have multiple values for each case in the switch statement:
The for loop loops through a block of code a specified number of times.
A function is a block of statements that can be used repeatedly in a program.
Information can be passed to functions as a parameter. Parameters act as variables inside the function.
If you want the function to return a value, you need to define the data type of the return value (such as int , string , etc), and also use the return keyword inside the function:
Go accepts recursion functions. A function is recursive if it calls itself and reaches a stop condition.
A struct (short for structure) is used to create a collection of members of different data types, into a single variable.
Maps are used to store data values in key:value pairs.