© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2021
T. LaversLearn to Program with Kotlinhttps://doi.org/10.1007/978-1-4842-6815-5_4

4. Binary Choices

Tim Lavers1  
(1)
Woonona, NSW, Australia
 

In the previous chapter, we learned how to iterate over the elements of an array, using a for-loop . This allowed us to automate the coloring of our tiles rather than setting the color of each individually. Now we will learn to make choices in our code based on expressions that evaluate as either true or false. Combined with looping, this will allow us to generate complex tile patterns with very few lines of code.

4.1 If-Else Statements

Consider the pattern in Figure 4-1. There are eight rows and columns, and the tiles are ...

Get Learn to Program with Kotlin: From the Basics to Projects with Text and Image Processing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.