C#之while与do……while语句
C#之while與do……while語句
? ? ? ? ? 循環(huán)語句
? ? ? ? ??C#提供了4中不同的循環(huán)機(jī)制
? ? ? ? ??For
? ? ? ? ??While
? ? ? ? ??do……while
? ? ? ? ??Foreach
?
? ? ? ? ??while語句
? ? ? ? ??循環(huán)只有一個表達(dá)式。
? ? ? ? ??C#中的while語句,和C++、Java中的while循環(huán)相同。
? ? ? ? ??while(Condition)
? ? ? ? ??{
???? ? ? ? ? ??Statement(s);
? ? ? ? ??}
? ? ? ? ??while循環(huán)用于以下情況
? ? ? ? ??在循環(huán)開始之前,不知道要重復(fù)執(zhí)行一個語句或語句塊的次數(shù)。
? ? ? ? ??Do……while
? ? ? ? ??根據(jù)條件判斷,來決定是否執(zhí)行重復(fù)執(zhí)行語句塊的語句。
? ? ? ? ??Do
? ? ? ? ??{
????? ? ? ? ?? Statements;
? ? ? ? ??}while(Condition)
? ? ? ? ??while和do……while的區(qū)別
? ? ? ? ??while語句是先判斷,再執(zhí)行。
? ? ? ? ??do……while是先執(zhí)行,再判斷。
總結(jié)
以上是生活随笔為你收集整理的C#之while与do……while语句的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#之switch多分支语句
- 下一篇: C#之for语句