Important characteristics of Go
This big section discusses important and essential Go features including variables, controlling program flow, iterations, getting user input, and Go concurrency. We begin by discussing variables, variable declaration, and variable usage.
Defining and using variables
Imagine that you wanted to perform some basic mathematical calculations with Go. In that case, you need to define variables to keep your input and your results.
Go provides multiple ways to declare new variables in order to make the variable declaration process more natural and convenient. You can declare a new variable using the var
keyword followed by the variable name, followed by the desired data type (we will cover data types in detail in Chapter 2, Basic Go Data Types). If you want, you can follow that declaration with =
and an initial value for your variable. If there is an initial value given, you can omit the data type and the compiler will guess it for you.
This...