Long-Row-First Repeats

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

What You'll Learn

The inner loop is the same shape as Program 9 (j from start to i), but the outer i counts down from E to A. That puts five Es on the first line, then four Ds, and so on, ending with a single A.

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

⭐ Pattern Output

Five rows from E down to A:

Output
EEEEE
DDDD
CCC
BB
A
1

Node.js / console version

Outer loop decreases i from end to start; inner loop runs j from start 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 = start; 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 = 65; 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--) picks which letter repeats: E first, then D, …, A.

Descending i
2

Inner loop: repeat count

for (let j = start; j <= i; j++) runs i - start + 1 times—the same inner pattern as Program 9.

Ascending j
3

Line break

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

New row
=

Program 9, lines reversed

The five line strings match Program 9 but appear in reverse order. Complexity O(n²).

💡 Tips for Enhancement

Try These

  • Contrast with Program 10: same outer E → A, different inner bounds
  • One-liner row: String.fromCharCode(i).repeat(i - start + 1)
  • Compare inner loop with Program 1 (there fromCharCode(j) advances the letter)

Avoid

  • Confusing with Program 10—inner j there runs E → i, not A → i
  • document.write after the document has loaded

Key Takeaways

1

Outer i: E → A; inner j: A → i.

2

Row lengths top-to-bottom: 5, 4, 3, 2, 1.

3

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

4

Same lines as Program 9, opposite vertical order.

5

Time complexity: O(n²).

❓ Frequently Asked Questions

Yes. Same inner loop and same five row strings; only the outer loop direction changes, so the lines print from EEEEE first down to A.
Both use outer i from E to A. Program 10 uses inner j from E down to i (short E row first). Program 11 uses inner j from A up to i (long E row first).
O(n²) for n rows from A to E.

Next: JavaScript Alphabet Pattern 12

Continue to the next program in the alphabet pattern series.

Program 12 →
Did you know?

Collect the lines from Program 9 from last to first and you get this pattern’s output for AE.

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