JAVA : What is a for-each loop in Java? SDET Automation Testing Interview Questions & Answers

preview_player
Показать описание

Level up your SDET and QA skills! 🚀 JAVA : What is a for-each loop in Java?

SDET Automation Testing Interview Questions & Answers

We will be covering a wide range of topics including QA manual testing, automation testing, Selenium, Java, Jenkins, Cucumber, Maven, and various testing frameworks.

JAVA : What is a for-each loop in Java?

A for-each loop in Java is a type of loop that is used to iterate over a collection of objects, such as an array or an Iterable object.

The syntax for a for-each loop is as follows:

for (type var : collection) {
// body
}

Here's an example:

int[] numbers = {1, 2, 3, 4, 5};

for (int n : numbers) {
}

In this example, we've created an array called numbers that contains the integers 1 through 5.

We've then used a for-each loop to iterate over the elements of the array and print them out.

The variable n takes on the value of each element of the array in turn, and the body of the loop simply prints out that value.

The output of this code is:

1
2
3
4
5
Рекомендации по теме
Комментарии
Автор

JAVA : What is a for-each loop in Java?

A for-each loop in Java is a type of loop that is used to iterate over a collection of objects, such as an array or an Iterable object.

The syntax for a for-each loop is as follows:

for (type var : collection) {
// body
}

Here's an example:

int[] numbers = {1, 2, 3, 4, 5};

for (int n : numbers) {
System.out.println(n);
}

In this example, we've created an array called numbers that contains the integers 1 through 5.

We've then used a for-each loop to iterate over the elements of the array and print them out.

The variable n takes on the value of each element of the array in turn, and the body of the loop simply prints out that value.

The output of this code is:

1
2
3
4
5

sdet_automation_testing
visit shbcf.ru