Main Page

Previous Next

Chapter 3: Loops and Logic


In this chapter we'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. We will cover:

  • 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 we will cover in this chapter, so make sure you have a good grasp of them.

But first, how do we make decisions in code, and so affect the way the program runs?

Previous Next
JavaScript Editor Java Tutorials Free JavaScript Editor