To print the Left Half Pyramid Pattern in Dart, we use nested loops where the outer loop controls the rows and the inner loop prints spaces and stars.
In this example,
n
, which is set to 5 in this example.n
, controlling the number of rows.n
and the current row, followed by stars equal to the current row number.void printLeftHalfPyramid() {
int n = 5;
for (int i = 1; i <= n; i++) {
String row = '';
for (int j = 1; j <= n - i; j++) {
row += ' ';
}
for (int k = 1; k <= i; k++) {
row += '*';
}
print(row);
}
}
void main() {
printLeftHalfPyramid();
}
* ** *** **** *****
In this tutorial, we learned How to print Left Half Pyramid Pattern in Dart language with well detailed examples.