4
Functions

A function is a reusable portion of code that accomplishes a specific task. Functions are a very important part of programming. In fact, programs are fundamentally a series of functions combined to accomplish more complex tasks.

You have worked with some functions already, like the println function, which is provided by the Kotlin standard library for printing data to the console. You can also define your own functions in code that you write. Some functions take in data required to perform a specific task. Some functions also return data, generating output that can be used elsewhere after the function has performed its task.

To get your function feet wet, you will start by using functions to organize NyetHack’s existing code. Then, you will define your own function to add an exciting new feature to NyetHack: a fireball spell.