Inspectopedia
 
2024.3

'while' loop can be replaced with enhanced 'for' loop

Warning
New
Last modified: 03 December 2024

Reports while loops that iterate over collections and can be replaced with enhanced for loops (foreach iteration syntax).

Example:

Can be replaced with:

This inspection depends on the Java feature 'For-each loops', which is available since Java 5.