Swift Program to Demonstrate the Nested While Loop

You are currently viewing Swift Program to Demonstrate the Nested While Loop

Swift program to demonstrate the nested while loop

// Swift program to demonstrate the 
// nested while loop

var cnt1:Int = 1;
var cnt2:Int = 1;

while(cnt1<=3)
{
    cnt2 = 1;
    while(cnt2<=cnt1)
    {
        print(cnt1);
        cnt2 = cnt2 + 1;
    }

    cnt1 = cnt1 + 1;
}

Output

1
2
2
3
3
3

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply