Enhanced for loop:

for (String element : array) {

    // rest of code handling current element
}

Traditional for loop equivalent:

for (int i=0; i < array.length; i++) {
    String element = array[i]; 

    // rest of code handling current element
}

Take a look at these forums: https://blogs.oracle.com/CoreJavaTechTips/entry/using_enhanced_for_loops_with

http://www.java-tips.org/java-se-tips/java.lang/the-enhanced-for-loop.html

Answer from user1920811 on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_for_loop.asp
Java For Loop
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-for-loop-with-examples
Java For Loop - GeeksforGeeks
1 week ago - Note: A "Time Limit Exceeded" error occurs when a program runs longer than the time allocated for execution, due to infinite loops. This is ideal for iterating over a known range or collection. Efficient syntax for initialization, condition checking, and incrementing.
Discussions

foreach - What is the syntax of the enhanced for loop in Java? - Stack Overflow
I have been asked to use the enhanced for loop in my coding. I have only been taught how to use traditional for loops, and as such don't know about the differences between it and the enhanced for... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a shorter way to write a for loop in Java? - Stack Overflow
In many cases max value is unknown (data from files, databases etc.). For me the best is loading everything to List (ArrayList etc.) and use for-each loop. Looping through collections is the best way to short loop syntax in my opinion. More on stackoverflow.com
๐ŸŒ stackoverflow.com
ELI5: Understanding For Loops in Java
we have 3 loop types: whie (condition) { // do this code } do { // run this code at least once } while (condition); // determines whether the loop should be ran more than once for (declaration; condition; iteration_step) { // do this code } people will often use i for a short lived loop variable - think of it as meaning iteration or something like that for (int i = 0; i < 5; i++) { // some code here } in this for loop we are declaring an int called i, saying to run the loop whilst i is less than 5 and the i++ is done once the body of the loop has been ran More on reddit.com
๐ŸŒ r/learnprogramming
5
0
April 14, 2021
What makes for-loops difficult for beginners?
The syntax of for loops in C-like languages is not exactly intuitive. Even the name "for" seems like a rather non-descriptive, meaningless word. I don't know how for loops are commonly taught, but perhaps it is common to see them introduced with examples like this: for (int i = 0; i < 10; ++i) print i; Now, it is true that the most common use of for loops is to repeat something a certain number of times like this, but if this is how for loops are introduced, then I can understand how they seem mysterious. What in the world is all that garbage syntax doing there for a simple counting loop? Why are there all of those semicolons, and why do you have to say ++i? Etc. It would be better, I think, to teach that the loop for (initialization; condition; update) statement; is (almost) equivalent to initialization; while (condition) { statement; update; } and then show several examples of the same code written in both of these ways to demonstrate and reinforce this equivalence. These examples should include not only the common case of repeating a statement a certain number of times, but also other uses of the for loop, such as finding the length of a C string (where the condition is like *p != '\0'). More on reddit.com
๐ŸŒ r/learnprogramming
7
2
March 30, 2013
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ tutorial โ€บ java โ€บ nutsandbolts โ€บ for.html
The for Statement (The Javaโ„ข Tutorials > Learning the Java Language > Language Basics)
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases. The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the "for loop" because of the way in which it repeatedly ...
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ for-loop
Java for Loop (With Examples)
If the condition is true, the body of the for loop is executed. The updateExpression updates the value of initialExpression. The condition is evaluated again. The process continues until the condition is false. To learn more about the conditions, visit Java relational and logical operators.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Java for loops are easy! ๐Ÿ”‚ - YouTube
#java #javatutorial #javacourse A for loop in Java is used to repeat a block of code a specific number of times, with control over initialization, condition,...
Published ย  December 5, 2024
Find elsewhere
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ java for loop
Java For Loop | Baeldung
3 weeks ago - Before the first iteration, the loop counter gets initialized, then the condition evaluation is performed followed by the step definition (usually a simple incrementation). ... The initialization, Boolean-expression, and step used in for statements ...
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ java-for-loop
Java For Loop
In this example, a nested for loop is used to create a grid-like output. The outer loop iterates over i, and for each iteration of i, the inner loop iterates over j.
๐ŸŒ
Medium
medium.com โ€บ javarevisited โ€บ understanding-the-java-for-loop-a-beginners-guide-20df0f83dde5
Understanding the Java for Loop: A Beginnerโ€™s Guide | by Mouad Oumous | Javarevisited | Medium
September 26, 2024 - The Java for loop, its structure, uses, and tips for writing efficient loops with increment, decrement, and nested loop examples.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ eli5: understanding for loops in java
r/learnprogramming on Reddit: ELI5: Understanding For Loops in Java
April 14, 2021 -

As the title said, can you guys help me understand the for loops in java like I'm five. I've been trying to learn java but when it comes to for loop, I'm having a hard time understanding it. Especially when my professor is using single letters like for int i, x, y, and such something like that. Whenever I'm coding, I always use proper names so I don't get confused with the variables. But I still get confused using for loops;-; so I mostly prefer using the do.. while or while loops. But I want to learn to understand it because I noticed my prof always uses it and as well as ytber programmers.

๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ understanding for loop in java with examples and syntax
Understanding For Loop in Java With Examples and Syntax
July 31, 2025 - Java provides three types of loops, i.e., โœ“ for loop โœ“ while loop โœ“ do-while loop. In this tutorial, you will learn all about for loop in Java. Start now!
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ loops-in-java
Java Loops - GeeksforGeeks
Increment/ Decrement: It is used for updating the variable for next iteration. Loop termination:When the condition becomes false, the loop terminates marking the end of its life cycle. Note: There is another form of the for loop known as Enhanced for loop or (for each loop). This loop is used to iterate over arrays or collections. Example: The below Java program demonstrates an Enhanced for loop (for each loop) to iterate through an array and print names.
Published ย  August 10, 2025
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ java_for_loop.htm
Java - for Loop
Modifies the loop counter at the end of each iteration. // Update example i++; // Increments i by 1 after each iteration ยท The following is the complete syntax of a for loop with all four components:
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ java-for-loop-example
Java For Loop Example
February 7, 2023 - You can use loops in programming to carry out a set of instructions repeatedly until a certain condition is met. There are three types of loops in Java: for loop. while loop. do...while loop. In this article, we'll focus on the for loop, its synt...
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ core java โ€บ java for loop
For loop Java
The most popular loop in Java is the so-called defined loop or for loop. For loop executes some statements for a certain number of times. For example, writing fifty times โ€œI must not be so, ho-ho, hoโ€ or sending invitations to all your friends are typical tasks for this kind of loop. The syntax ...
Published ย  July 23, 2024
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ java-for-loop
Java For Loop Syntax and Example - DataFlair
May 8, 2024 - We will be learning about for loops Currently in Loop. value of i = 0 Currently in Loop. value of i = 1 Currently in Loop. value of i = 2 Currently in Loop. value of i = 3 Currently in Loop. value of i = 4 Currently outside Loop. value of i = 5 ยท package com.dataflair.javaforloop; import java.io.*; public class ArrayTraverse{ public static void main(String []args) { int arrp[] = {1,2,3,4,5,6}; for(int i=0;i<arrp.length;i++) { System.out.println("The "+(i+1)+" element is "+arrp[i]); } } }
๐ŸŒ
Zero To Mastery
zerotomastery.io โ€บ blog โ€บ enhanced-for-loop-java
How To Use Enhanced For Loops In Java (aka 'foreach') | Zero To Mastery
January 26, 2024 - The syntax of the enhanced for loop is elegantly simple. ... parentheses: Inside the parentheses, we first declare a variable of the same type as the elements in the array or collection.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ enhanced-for-loop
Java for-each Loop (With Examples)
In Java, the for-each loop is used to iterate through elements of arrays and collections (like ArrayList).
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ enhanced-for-loops-in-java-how-to-use-foreach-loops-on-arrays
Enhanced For Loops in Java โ€“ How to Use ForEach Loops on Arrays
February 17, 2023 - They simplify how you create for loops. For instance, the syntax of a for loop requires that you create a variable, a condition that specifies when the loop should terminate, and an increment/decrement value.