06 June 2023

Explain For-Each Loop In Java - learngreen.net

 An enhanced for loop in Java is a short way to go through items in a group, like an array or a collection. It's also called a "for-each" loop. It makes going through a group of things easier by doing the counting automatically. To create an enhanced for loop in Java, use this syntax

for (type var : array) {

   //code block

}

Working of For-Each Loop:-

You can loop through a group of things like an array, list, or set. The word "type var" tells us what kind of things are in the collection. It can be any type of information used in Java programming. The loop looks at each thing in a group and puts it into a box called "var." The computer does the instructions in the loop for each thing in the list.

Explain For-Each Loop In Java
Image | Eclipse IDE





No comments:

Post a Comment