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 - Java Tutorial
From the course: Java 8 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Programming conditional logic3m 45s
-
(Locked)
Using the switch statement4m 51s
-
(Locked)
Creating looping code blocks5m 23s
-
(Locked)
Creating reusable code with methods4m 15s
-
(Locked)
Overloading methods with different signatures4m 51s
-
(Locked)
Passing arguments by reference or by value4m 47s
-
(Locked)
Challenge: Creating a more complex calculator application1m 53s
-
(Locked)
Solution: Creating a more complex calculator application3m 23s
-
(Locked)
-
-
-
-
-
-