In C # This programming language, and Java is the same, while the loop is the first to judge the loop. There are many textbooks, like to give some more complex examples to introduce the use of while loop. I think it's a simple matter of simplifying the problem and letting the reader know The use of the while loop.
Example 1: Calculates The sum of the numbers from 1 to ten.
Console.WriteLine(" start calculating from 1 to ten and:" );
intnum;
intsum;
num=0;
sum=0;
while(num<=Ten)
{
Sum=sum+num;
num=num+1;
}
Console.WriteLine("1 to ten and for " +sum);
Example 2: Countdown.
usingSystem;
usingSystem.Threading;
namespaceyywx14
{
class Program
{
Public Static void Main(string[] args)
{
// start countdown:
Console.WriteLine(" Start the countdown:" );
intnum;
num=Ten;
while(num>0)
{
Console.WriteLine(num);
Thread.Sleep( +);
num=num-1;
}
Console.WriteLine("The countdown is over!" ");
Console.ReadKey();
}
}
}
This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1970217
14. The loop structure inside C #: use of While