Modifying Variable Values
We've learned how to declare a variable. Now, let's understand how to modify the value of a variable.
Take a look at the following program, which prints the value of myVariable
using the Println
function:
index.go
We can use the following syntax for assigning a different value to the variable:
index.go
Notice that this time, we omit the var
keyword because we are not declaring a new variable. Now, let's add this line to the program:
index.go
In the code above, we employed the var
keyword to declare a variable. Alternatively, we can use the :=
operator for variable declaration. In such a case, the code will appear as follows:
index.go
Все було зрозуміло?
Зміст курсу
Introduction to GoLang
Introduction to GoLang
Modifying Variable Values
We've learned how to declare a variable. Now, let's understand how to modify the value of a variable.
Take a look at the following program, which prints the value of myVariable
using the Println
function:
index.go
We can use the following syntax for assigning a different value to the variable:
index.go
Notice that this time, we omit the var
keyword because we are not declaring a new variable. Now, let's add this line to the program:
index.go
In the code above, we employed the var
keyword to declare a variable. Alternatively, we can use the :=
operator for variable declaration. In such a case, the code will appear as follows:
index.go
Все було зрозуміло?