Reader small image

You're reading from  Android Programming with Kotlin for Beginners

Product typeBook
Published inApr 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789615401
Edition1st Edition
Languages
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

Making decisions in Kotlin


Our Kotlin code will constantly be making decisions. For example, we might need to know whether the user has new messages, or whether they have a certain number of friends. We need to be able to test our variables to see whether they meet certain conditions, and then execute a specific section of code depending upon whether they did or not.

In this section, as our code gets more in-depth, it helps to present the code in a way that makes it more readable. Let's take a look at code indenting to make our discussion about making decisions easier.

Indenting code for clarity

You have probably noticed that the Kotlin code in our project is indented. For example, the first line of code inside the MainActivity class is indented by one tab. Additionally, the first line of code is indented inside each function by another tab; here is an annotated diagram to make this clear:

Notice that when the indented block has ended, often with a closing curly brace (}), it is indented to...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Android Programming with Kotlin for Beginners
Published in: Apr 2019Publisher: PacktISBN-13: 9781789615401

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton