Decisions
Our Java 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 certain section of code depending upon whether it did or not.
In this section, as our code gets more in-depth, it helps to present it in a way that makes it more readable. Let's take a look at code indenting to make our discussion about decisions easier.
Indenting our code
You have probably noticed that the Java code in our projects is indented. For example, the first line of code inside the MainActivity
class is indented by one tab. And the first line of code is indented inside each method. Here is an annotated image as another quick example to make this clear:
Notice also that when the indented block has ended, often with a closing curly brace }
, that }
is indented to the same extent as the line of code that began...