To print a Rhombus Pattern in TypeScript, we use nested loops. The outer loop controls the number of rows, and the inner loops control the spaces and stars (*) to form the pattern.
In this example,
n
to the desired number of rows in the rhombus.for
loops, where the outer loop runs from 1 to n
and the inner loops control the spaces and stars in each row.const n: number = 5;
for (let i: number = 1; i <= n; i++) {
let row: string = '';
for (let j: number = 1; j <= n - i; j++) {
row += ' ';
}
for (let k: number = 1; k <= n; k++) {
row += '*';
}
console.log(row);
}
***** ***** ***** ***** *****
In this tutorial, we learned How to print Rhombus Pattern in TypeScript language with well detailed examples.