[C#基礎]-C# While Loop 中 n++的擺放位置比較
[C#基礎]-C# While Loop 中 n++的擺放位置比較
本篇要分享C# While Loop 中 n++的擺放位置比較範例,有興趣的同好,歡迎來一下哈哈 ^ ^。
拷貝來源:http://msdn.microsoft.com/zh-tw/library/2aeyhxcd(v=vs.90).aspx
ex01:
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
*/
|
ex02:
class WhileTest2
{
static void Main()
{
int n = 1;
while (n++ < 6)//先執行n<6的比較,之後在執行n++動作
{
Console.WriteLine("Current value of n is {0}", n);
}
}
}
/*
Output:
Current value of n is 2
Current value of n is 3
Current value of n is 4
Current value of n is 5
Current value of n is 6
*/
|