Triangle pattern program in Swift

Traingle pattern program in swift programming language from the basics to understand the pattern program using the numbers to print the pattern programs

func pattern(_ int : Int)
{
for i in 1...int
{
print(String.init(repeating:" ",count:int-i)+String.init(repeating:"1",count: 2*i - 1))
}
}
pattern(8)

 

Output:

       1                                                                                                                   

      111                                                                                                                     

     11111                                                                                                                    

    1111111                                                                                                                   

                                                                                

What is pattern program in swift

Pattern programs are simply patterns made up of integers, alphabets, or symbols in a specific order. The for loop condition can be used to solve these types of pattern programs quickly. There are two or more loops in each pattern program. The number of loops is determined by the pattern or logic’s complexity. The first for loop affects the row, whereas the second affects the column.