Step-by-Two Alphabet Rows

Beginner
⏱️ 8 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Outer i += 2

What You'll Learn

The inner loop is the same idea as Program 1: for each row, print String.fromCharCode(j) with j from A through the current i. The twist is the outer loop: i jumps by two each time (65, 67, 69, 71, 73), so each row is two letters wider than the previous row’s span requires—giving odd lengths 1, 3, 5, 7, 9.

Total letters: \(1 + 3 + 5 + 7 + 9 = 25\). The reference snippet declared k but never used it; clean code only needs i and j.

⭐ Pattern Output

Five rows with i from 65 to 73, step 2:

Output
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
1

Node.js / console version

Outer loop uses i += 2; upper bound 73 is the last row cap (ASCII for I). You can name the bound outerEnd for clarity:

JavaScript
const start = "A".charCodeAt(0);
const outerEnd = "I".charCodeAt(0); // 73 — last row prints A..I

for (let i = start; i <= outerEnd; i += 2) {
  let line = "";
  for (let j = start; j <= i; j++) {
    line += String.fromCharCode(j);
  }
  console.log(line);
}
2

Browser version (document.write)

Same logic as the reference: for (i = 65; i <= 74; i += 2) stops after the row with i === 73 because the next i would be 75 > 74:

HTML
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 65; i <= 74; i += 2) {
  for (let j = 65; j <= i; j++) {
    document.write(String.fromCharCode(j));
  }
  document.write("<br>");
}
</script>
</body>
</html>

🧠 How It Works

1

Outer loop: i += 2

i takes values 65, 67, 69, 71, 73 — the last row ends at I.

Wider rows
2

Inner loop: A to i

for (let j = start; j <= i; j++) prints the forward alphabet from A through the current i.

Same as Program 1
3

Line break

After each row, console.log(line) or document.write("<br>").

New row
=

Odd row lengths

Each row adds two more characters than the previous. Total 25 letters through I. Complexity scales with the sum of row widths.

💡 Tips for Enhancement

Try These

  • Compare side by side with Program 1 (i++ vs i += 2)
  • Try i += 3 and adjust the outer limit to see new width gaps
  • Use outerEnd as the character code of the last letter you want on the bottom row

Avoid

  • Copying the unused k from some older snippets — it is not part of the logic
  • document.write after the document has loaded

Key Takeaways

1

Outer step 2 makes row lengths 1, 3, 5, 7, 9.

2

Inner loop prints fromCharCode(j) from A to i.

3

Last row ends at I (code 73).

4

Total letters printed: 25.

5

HTML version may use i <= 74 as in the original; effect matches i <= 73 with step 2.

❓ Frequently Asked Questions

After i = 73 the next value would be 75, which fails i <= 74, so the loop still runs exactly five times. Using outerEnd = 73 (I) in the Node example states the last row letter directly.
No. The published HTML only uses i and j. Some tutorials add extra declarations by mistake; you can omit k.
For this fixed pattern, inner iterations total 25. If you generalize to many rows with growing width, work is on the order of the sum of row lengths (quadratic in typical triangle scaling).

Next: JavaScript Alphabet Pattern 15

Mirror bowtie with letters and a growing star band.

Program 15 →
Did you know?

The row widths 1, 3, 5, 7, 9 are the first five odd numbers; their sum is a perfect square: 5² = 25.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful