Logo

Programming-Idioms

History of Idiom 7 > diff from v148 to v149

Edit summary for version 149 by reilas:
[Java] Re-factor

Version 148

2024-04-29, 21:57:18

Version 149

2024-11-03, 21:37:29

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
Imports
import static java.lang.System.out;
Code
for (int i = 0; i < items.length; i++) {
    T x = items[i];
    System.out.printf("Item %d = %s%n", i, x);
}
Code
int i, n;
for (i = 0, n = items.length; i < n; ++i)
    out.println(i + " = " + items[i]);
Comments bubble
items is an array.
Comments bubble
items is an array.