235k views
3 votes
Write a nested loop in a programming language that displays 10 rows of asterisks, demonstrating a simple code structure.

User Drewm
by
8.5k points

1 Answer

2 votes

Final answer:

To display 10 rows of asterisks using a nested loop in a programming language (like Python), you can use two nested loops: an outer loop that iterates over the rows and an inner loop that prints the asterisks for each row.

Step-by-step explanation:

To display 10 rows of asterisks using a nested loop in a programming language (like Python), you can use two nested loops: an outer loop that iterates over the rows and an inner loop that prints the asterisks for each row.

  1. Start by initializing a variable called 'rows' with the value 10.
  2. Create an outer loop that runs for 'rows' number of times.
  3. Inside the outer loop, create an inner loop that runs for the current value of the 'rows' variable.
  4. Inside the inner loop, print an asterisk (*) to display the asterisks for each row.

The code snippet in Python would look like:

rows = 10
for i in range(rows):
for j in range(i + 1):
print('*', end=' ')
print()

User DSlagle
by
8.1k points