Descending Repeat Rows

Beginner
⏱️ 8 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Outer E → A

What You'll Learn

Like Program 9, each row repeats a single letter and row lengths are 1, 2, …, 5. Here i counts down from E to A, and the inner loop runs j from end down to i so there are end - i + 1 copies of String.fromCharCode(i).

Total characters: \(1 + 2 + 3 + 4 + 5 = 15 = n(n+1)/2\) for five rows.

⭐ Pattern Output

Five rows from E down to A:

Output
E
DD
CCC
BBBB
AAAAA
1

Node.js / console version

Outer loop decreases i from end to start; inner loop runs j from end down to i, printing fromCharCode(i) each time:

JavaScript
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);

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

Browser version (document.write)

Same logic with ASCII codes 6569. Save as .html or use the live editor:

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

🧠 How It Works

1

Outer loop: row letter

for (let i = end; i >= start; i--) walks from E down to A. That letter is repeated for the whole row.

Descending i
2

Inner loop: repeat count

for (let j = end; j >= i; j--) runs end - i + 1 times. The body always appends String.fromCharCode(i).

Same as Program 9 count
3

Line break

After the inner loop, console.log(line) or document.write("<br>").

New row
=

Same lengths as Program 9

Both use row lengths 1, 2, …, n. Program 9 assigns the k-th row to the k-th letter from A; Program 10 assigns it to the k-th letter counting down from E. Complexity O(n²).

💡 Tips for Enhancement

Try These

  • Compare with Program 9: same repeated-letter idea and row lengths; loops walk A → E vs E → A
  • One-liner row: String.fromCharCode(i).repeat(end - i + 1)
  • Notice the inner bounds match Program 2, but Program 2 prints fromCharCode(j)

Avoid

  • Printing fromCharCode(j) here — that becomes Program 2’s triangle, not repeated letters
  • document.write after the document has loaded

Key Takeaways

1

Outer i: E → A; inner j: E → i (descending).

2

Each row repeats one letter; lengths are 1, 2, 3, 4, 5.

3

Total characters: \(n(n+1)/2\).

4

Same row lengths as Program 9; letters run E → A instead of A → E.

5

Time complexity: O(n²).

❓ Frequently Asked Questions

Both repeat String.fromCharCode(i) per row with lengths 1 … n. Program 9 uses outer i ascending and inner j from start to i; Program 10 uses outer i descending and inner j from end to i. The first row is A vs E.
Same nested bounds (j from E down to i, outer i from E down to A). Program 2 uses fromCharCode(j) so each position shows a different letter; Program 10 uses fromCharCode(i) so the row is uniform.
O(n²) for n rows from A to E.

Next: JavaScript Alphabet Pattern 11

Continue to the next program in the alphabet pattern series.

Program 11 →
Did you know?

Program 9 uses i from A up and j from start to i; Program 10 uses i from E down and j from end to i—both repeat fromCharCode(i) for the same row lengths.

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