We talk about splitting up the flow of a program across branches with if statements. Even with branching, our program steadily advances, always getting closer to the end of our program. Sometimes, however, we’d like to go back to code that we’ve executed before. This is called a loop.
Loops come in several forms in Java, and today, we will focus on one. I am ashamed at the number of resources for learning that start by enumerating every possible tool available to you. That is useful information delivered at the wrong time. Let’s meet while:
// pre loop workwhile (booleanCondition) {
// work to repeat// update terms of boolean condition
}
// post loop work
We’ll write a few while loops to accomplish the following tasks:
Write a countdown application.
Write a flashcard app for practicing with the mod operator.
Write an app that prompts you to complete an acrostic.
Write an app that hijacks the mouse and spins it in a circle.