From the course: Java 8 Essential Training

Unlock the full course today

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

Creating looping code blocks

Creating looping code blocks - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Creating looping code blocks

- Java provides a number of ways of looping through collections of data. In this project, Loops, I've declared an array of strings. The brackets after the data type String means that this is an array of values, and the array has 12 items. One for each month of the year. I'll demonstrate how to loop through this data using four different types of loops. An incrementing loop, a for each loop, a while loop, and a do while loop. I'll start with an incrementing loop. To create the skeleton of an incrementing loop in IntellJ IDEA, type fori and press enter. And that will use a code template. An incrementing loop has three statements between parenthesis. The first declares a counter-variable, a starting point. The second is a condition and the loop will continue as long as that condition is true. And the third part is an incremental statement, i++ means increment the value by one. I'll set my condition to i < months.length, so I'll keep looping as long as the value doesn't match the length…

Contents