Know the loops…
Posted by Satyen Pandya | Posted in .Net | Posted on 19-05-2011
0
Normally, we use loops for repeating few lines of codes to achieve some definitive task. As far as good programming is concern, we are advised not to use goto statements. But internally, compiler generates the goto statements for the loop we have written.
In this post we see how different loops (While, For and Foreach) converted after compilation.
(1) while
The while statement executes a statement or a block of statements until a specified expression evaluates to false.
Example
class WhileTest
{
static void Main()
{
int n = 1;
while (n < 6)
{
Console.WriteLine("Current value of n is {0}", n);
n++;
}
}
}
/*
Output:
Current value of n is 1
Current value of n is 2
Current value of n is 3
Current value of n is 4
Current value of n is 5
*/











Satyens' Portfolio