Search⌘ K
AI Features

Solution Review: Print Pattern using Nested Loops

Understand how nested loops work to print patterns by reviewing a solution implemented in both Python and PowerShell. Learn the role of outer and inner loops for controlling rows and columns, and grasp syntax differences like print statements in both languages.

Solution

Let’s go over the solution to the challenge in Powershell and Python.

Python

Python 3.5
for i in range(0, 5): # Outer loop define the number of rows
for j in range(0, i+1): # Inner loop is used to define number of column in each row
# printing stars
print("*",end="")
print("\n") # Here the programs move to the next line

Explanation

  • Line: 1-2 Here, we have defined two loops; the outer loop is used to define the number of rows while the inner loop is used to
...