I have a C program like this that I want to translate to Swift:
int main(void)
{
int i, j;
for(i=1;i<=5;i++)
{
printf("\n");
for(j=1;j<=5-i;j++)
{
printf("_");
}
for(j=1;j<=i;j++)
{
printf("%d",j);
}
for(j=i-1;j>=1;j--)
{
printf("%d",j);
}
}
printf("\n");
}
Output:
1
121
12312
1234123
123454321
I'm learning Swift and I wanted to make this pattern but I'm stuck with the conditions in the 3rd loop.
What should I be writing there?
Swift code:
import Foundation
var no = 1
for i in 1...5
{
no = 1
for j in 1..<(6-i)
{
print("_" , terminator : " ")
}
for k in 1...i
{
print("\(no)", terminator : " ")
no+=1
}
for l in // 3rd loop , what would be the conditions ?
}
print("\n")
}
