Triangle using While Loop in Python

Printing Triangle using While Loop in Python programming. While Loop allows code to be executed and repeat a specific block of code until the boolean condition is met.

Program While Loop using Break Statement

Program

a  = 0
while a <= 10: #loop looping from 0 to 10.
    if a == 5: #if 'a' value equal to 5 then
        print("The Statement is Break on 5")
        break #break the process.
    print(a)
    a = a + 1
Output
0
1
2
3
4
The Statement is Break on 5

Program Printing Triangle using While Loop

Program

a = 0
while a <= 10: #loop looping from 0 to 10.
    b = 0
    while b <= a: #loop looping from 0 to 'a' value.
        print("* ", end="") #and printing '*',
        b += 1 #adding 1 to 'b' value.
    print() #used for New Line.
    a += 1 #adding 1 to 'a' value.
Output
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *