Posted on February 19, 2022 by Andrzej Dubaj
The for-each loop examines the values of the list in order one at a time. The expression is defined in the following format: for (TypeOfVariable nameOfVariable: nameOfList), where TypeOfVariable is the list’s element type, and nameOfVariable is the variable that is used to store each value in the list as we go through it.
The for-each loop described above hides some parts of the for-loop we practiced earlier. The for-each loop would look like this if implemented as a for-loop: