Java For Loop

For Loop Basics

Syntax: for (int i = 0; i < n; i++) { /* code */ }

Enhanced For Loop

Syntax: for (Type item : collection) { /* code */ }

Use Cases

Use for loops when you know the number of iterations or need to iterate over arrays/collections.