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();
}


Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Feb 18, 2015, 10:53 PM EST
Nanhe SiddiqueRank #1,103 · 1.7K reputationPosted Feb 19, 2015, 12:23 AM EST
----*
---***
--*****
-*******
*********
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 19, 2015, 12:54 AM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 19, 2015, 2:02 AM EST
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.
Vikram AgrawalRank #4,713 · 329 reputationPosted Feb 19, 2015, 3:50 AM EST
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