Which of the following can loop through an array without referring to the elements by index?



Which of the following can loop through an array without referring to the elements by index?

A. do-while loop

B. for (traditional)

C. for-each

D. while

Answer:

C. for-each

Explanation:

While a traditional for loop often loops through an array, it uses an index to do so, making Option B incorrect. 

The for-each loop goes through each element, storing it in a variable. Option C is correct.

Free Spring Boot Tutorial - 5 Hours Full Course


Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course

Comments