In this chapter, you will learn how to define rules for when code should be executed.
This language feature is called control flow, and it allows you to describe the conditions for when specific portions of your program should run.
You will see the if/else
statement and expression and the when
expression, and you will learn how to write true/false tests using the comparison and logical operators.
Along the way, you will also take a look at Kotlin’s string templating feature.
To see these concepts in action, you will begin building a project called NyetHack, which you will work on through most of this book.
Why “NyetHack”? We are glad you asked. Perhaps you remember NetHack, a game released in 1987 by The NetHack DevTeam. NetHack was a single-player text-based fantasy game with ASCII graphics; check it out at nethack.org. You will be building elements of a similar text-based game (no awesome ASCII graphics, though – sorry). JetBrains, the creator of the Kotlin language, has offices in Russia; when you put together a text-based game like NetHack and Kotlin’s Russian origins, you get NyetHack.