Logo

Programming-Idioms

History of Idiom 7 > diff from v150 to v151

Edit summary for version 151 by reilas:
[Java] edit

Version 150

2024-11-03, 21:38:33

Version 151

2024-11-03, 21:42:34

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Imports
import java.util.ArrayList;
Imports
Code
int i = 0;
for(String x : items) {
	System.out.printf("%d %s%n", i, x);
	i++;
}
Code
int i = 0;
for (T t : items)
    out.println(i++ + " = " + t);