Use nested while loop to print stars(*)in patterns

n=5
i = 0 # initialize to zero for outer loop 
j = 0 # initialize to zero for inner loop
while i<=n:
               # outer loop runs n times
                while j < i:
                        #inner loop runs n times 
print("*",end="")
                     j += 1 # increment before checking inner loop condition 
              j = 0          # re-initialize after leaving inner loop 
 i += 1        #  increment before checking outer loop condition 
print('')

Hey @DevendraMokat, and welcome to Ask!

Could you clarify what you need help with?

3 Likes