Chapter 3. Loops and Logic
In this chapter you'll look at how you make decisions and choices in your Java programs. You will also learn how to make your programs repeat a set of actions until a specific condition is met. In this chapter you'll learn:
How you compare data values
How you can define logical expressions
How you can use logical expressions to alter the sequence in which program statements are executed
How you can select different expressions depending on the value of a logical expression
How to choose between options in a fixed set of alternatives
How long your variables last
How you can repeat a block of code a given number of times
How you can repeat a block of code as long as a given logical expression is true
How you can break out of loops and statement blocks
What assertions are and how you use them
All your programs of any consequence will use at least some, and often most, of the language capabilities and programming techniques I will cover in this chapter, so make sure you have a good grasp of them.
But first, how do you make decisions in code, and so affect the way the program runs?
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access