hello friends,
i am having a doubt,
here there are four for loop statement are there,
example:
here n = 5;
first for loop check the => i => 1 <=5 condition true than move to next loop called j.
now second => j = 0 , 0< 4 condition true than print the space
now my doubt is, when the third for loop will execute whether the second loop got over or when.
please tell me anyone detaily..
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < (n - i); j++)
Console.Write(" ");
for (int j = 1; j <= i; j++)
Console.Write("*");
for (int k = 1; k < i; k++)
Console.Write("*");
Console.WriteLine();
}

Vikram AgrawalPosted Feb 19, 2015, 8:50 AM
Hi Seenu,
See here you have one outer for loop and 3 inner for loop inside your outer for loop. so all 3 inner for loop will execute one by one, i.e. after completion of 1st loop the 2nd loop will execute and same for the rest inner loops.
Your outer loop is creating rows, and 1st inner loop is creating white spaces before the *. 2nd and 3rd loop is for print the *.
It will create the pattern like below
*
* * *
* * * * *
* * * * * * *
in this 2nd loop will create this pattern
*
* *
* * *
* * * *
* * * * *
Thanks
VulpesPosted Feb 19, 2015, 7:02 AM
It's now clear that the outer for loop contains three nested for loops. The bodies of all three of the inner loops contain one statement and are independent of each other i.e. there is no inner nesting.
Jignesh TrivediPosted Feb 19, 2015, 5:54 AM
AS per the code third for loop will execute after finish of 2nd for loop...
As suggested by Manish, you may debug this this give you all answer of question.
hope this will help you.
Nanhe SiddiquePosted Feb 19, 2015, 5:23 AM
----*
---***
--*****
-*******
*********
in this fisrt for loop determine no of stair
second for loop print space here i shown space with - (hyphen)
third and forth loop print *
to understand in depth try dry run and make a chart of i,j,k, variable on papers
Manish Kumar ChoudharyPosted Feb 19, 2015, 3:53 AM