Ch 4: Loops in Java

About This Chapter

Learn about loops in Java with this Java tutorial chapter. Using short and engaging lessons, this chapter will help you understand the functions and purposes of several types of loops that are commonly used in the Java programming language.

Loops in Java: Chapter Summary

This collection of Java tutorial lessons provides clear and straightforward instruction on the types of loops that are used in Java. The chapter covers the basics of while loops, do-while loops, for loops and more. You'll also see illustrative examples of these loops in action and learn about their syntax.

These lessons break down Java loop concepts into bite-sized chunks so you can easily follow and retain the information. After completing each lesson, you can make sure you fully understand the information by taking short multiple-choice quizzes.

These lesson go over several Java loop topics, including:

  • For loops and nested for loops
  • Syntax of while and do-while loops
  • Nested while and infinite while loops

Java is a trademark of the Oracle Corporation, which is not affiliated with

6 Lessons in Chapter 4: Loops in Java
Test your knowledge with a 30-question chapter practice test
For Loops in Java: Syntax & Example

1. For Loops in Java: Syntax & Example

This lesson will cover for loops in Java. A for loop is a counting loop, because it repeats a set of instructions for a set number of times. For loops are useful when you know when the condition will be met.

Nested For Loops in Java

2. Nested For Loops in Java

A loop within a loop: nested for loops in Java are a way to perform more complicated tasks and routines. In this lesson, we'll learn the syntax for nested loops and also look at some examples.

While Loops in Java: Example & Syntax

3. While Loops in Java: Example & Syntax

This lesson will cover the Java while statement, which loops through lines of code while a specific value or condition is true. While loops are very powerful, but they should be carefully developed and tested.

Do-While Loops in Java: Syntax & Example

4. Do-While Loops in Java: Syntax & Example

Programming is about repetitive tasks: The Java Do-While loop is great for performing a specific set of instructions while a condition is true. In this lesson, we'll cover the syntax and provide some real-world code examples.

Nested While Loops in Java

5. Nested While Loops in Java

How would you print out a chart to record scores for players in a basketball game? In Java, you can do this using a nested while loop. In this lesson, we'll explore how to use nested while loops in Java.

Infinite While Loops in Java

6. Infinite While Loops in Java

Infinity is a daunting concept, and in Java, an infinite loop can be a nightmare. In this lesson, we'll break down the concept of an infinite/unending loop in Java and provide examples and caveats.

Chapter Practice Exam
Test your knowledge of this chapter with a 30 question practice chapter exam.
Not Taken
Practice Final Exam
Test your knowledge of the entire course with a 50 question practice final exam.
Not Taken

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.