Skip to content

The for loop

Read · 1 of 5

Three parts in the brackets

for (int i = 1; i <= 3; i++) { … }: start i at 1; keep going while i <= 3; after each round, do i++.

The block runs once per value of i: 1, 2, 3. Counting from 0 with i < n runs exactly n times, the most common loop in DSA.