Var
Variables are used to store data.
Each variable has a type that defines the type of the data that it holds.
Variables are declared using the var keyword:
==============================
var num: Int = 42
==============================
We have declared a variable called num of type Int, and assigned the value 42 to it.
Now we can use num in our code, for example output its value using println():
println(num)
==============================
You can also declare variables using the val keyword:
==============================
The difference with var is that variables declared using val cannot be changed.
Коментарі