From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create looping code blocks

Create looping code blocks - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Create looping code blocks

- [Instructor] Java provides a number of ways of looping through collections of data. I'm going to show how to iterate through a collection of data in a few different ways. In this starting application, I've created an array of strings, each value representing one month of the year. So there are 12 values and I want to display each of them in the console. The first kind of loop I'll show is sometimes called an iterative loop. You can generate this code by typing fori and pressing enter, return, or tab and that will expand to the template you need. This kind of loop uses three expressions. Separated with semicolons. The first declares a variable, typically a numeric value. And when you're looping through a collection of data, it's typically initially set to zero. And that's because Java uses zero based indexing. The first item in the array is set to be at index zero, the second at index one, and so on. The next is the…

Contents