October 2014
Beginner to intermediate
285 pages
6h 24m
English
An if statement lets you make decisions in code and optionally run a piece of code depending on whether a condition is true. This is how you make a computer “think.”
It’s just like the real world. We run on “if” statements all the time. If your age is >= 16, you are allowed to drive. If the door is unlocked, you can open it, or else you cannot. If the command given to Minecraft is equal to "hello", then send a message. If your health drops to zero, you’re dead.
This is what it looks like in Java:
| | if (something) { |
| | // run this code... |
| | } |
The part in parentheses (something) can be anything that turns out true or false; in other words, a Boolean condition (more on that in just a second).
If you ...
Read now
Unlock full access