Power Your Software Testing
with AI and Cloud
Supercharge QA with AI for Faster & Smarter Software Testing

In Java, for-each loop traverses an array or collection of elements one by one. In place of declaring and initializing a loop counter variable, you declare a variable of the same type as the array's base type, followed by a colon and the array name.
Syntax:
for (type var : array)
{
//statements to be executed
} Let’s look at the following Java program using a for-each loop that prints the elements of an Array.
class Example {
public static void main(String[] args) {
int[] num = {1, 3, 5, 7};
// for each loop
for (int num1: num) {
System.out.println(num1);
}
}
}
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.

Get 100 minutes of automation test minutes FREE!!