Defining functions

To define a function, we have to use the fun keyword; this also can be declared as a first class citizen. This means that a function can only be defined in a file. We will touch on functions in greater detail in the Functions section, but for now, let's look at a simple example that changes the value of the mutable variable:

fun changeMutable() {
mutable = 4
}

In the previous snippet, we can see that the changeMutable function can be declared as a first class citizen in the same file as the mutable variable, or in any other place.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.186.178