- Đối với do thường đi với while hay còn gọi vòng lặp do-while: thực thi các tuyên bố trong dấu ngoặc {} đến khi điều kiện trong while() thì sẽ kết thúc.
Xem mã sau:
public class TestDoWhile
{
public static void Main ()
{
int x = 0;
do
{
Console.WriteLine(x);
x++;
} while (x < 5); // chú ý dấu ';' là bắt buộc
}
}
/*
Output:
0
1
2
3
4
*/
+ While
- Nó thực thi các tuyên bố trong dấu {} đến khi gặp điều kiện thì chấm dứt.
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
*/
016. Keyword [do] [while]
Related Tags :WritingObsolete
No comments:
Post a Comment
Commets Download Photoshop Actions, Lightroom Presets, PSD Template, Mockups, Stocks, Vectors, Fonts. Download free